Skip to main content

ContextAgent

The ContextAgent is a specialized agent for Context Engineering - comprehensive codebase analysis and Product Requirements Prompt (PRP) generation.
Not to be confused with Context Window Management (context=ContextConfig()). This agent analyzes codebases and generates implementation guidance, while ContextConfig manages token budgets and compaction.

Quick Start

from praisonaiagents import create_context_agent

# Create context engineering agent
agent = create_context_agent(
    llm="gpt-4o-mini",
    name="Context Engineering Specialist"
)

# Analyze a codebase
analysis = agent.analyze_codebase_patterns(
    project_path="/path/to/project",
    file_patterns=["*.py"]
)

# Generate PRP (Product Requirements Prompt)
prp = agent.generate_prp(
    feature_request="Add user authentication with JWT",
    context_analysis=analysis
)

Key Features

FeatureDescription
Codebase AnalysisAnalyze project structure, patterns, conventions
AST AnalysisExtract classes, functions, imports from Python
Pattern ExtractionIdentify code patterns and architecture
PRP GenerationCreate comprehensive implementation guidance
Validation FrameworkDefine success criteria and quality gates
Implementation BlueprintStep-by-step implementation plan
GitHub IntegrationAnalyze GitHub repositories directly

API Reference

Core Methods

# Protocol-compatible methods (recommended)
analysis = agent.analyze_codebase("/path/to/project")
prp = agent.generate_prp("Feature description", analysis)
blueprint = agent.create_implementation_blueprint("Feature", analysis)

# Original methods (still available)
analysis = agent.analyze_codebase_with_gitingest("/path/to/project")
prp = agent.generate_comprehensive_prp("Feature description", analysis)
blueprint = agent.build_implementation_blueprint("Feature description", analysis)

Async Methods

# Async versions for non-blocking execution
analysis = await agent.aanalyze_codebase("/path/to/project")
prp = await agent.agenerate_prp("Feature description", analysis)
blueprint = await agent.acreate_implementation_blueprint("Feature", analysis)

Configurable Output

Control output using the output= parameter (inherited from Agent):
# Silent mode - suppress all progress output
agent = create_context_agent(llm="gpt-4o-mini", output="silent")

# Verbose mode - show rich output with progress
agent = create_context_agent(llm="gpt-4o-mini", output="verbose")

# Actions mode - show actions/steps only
agent = create_context_agent(llm="gpt-4o-mini", output="actions")

# Default is silent (no output)
agent = create_context_agent(llm="gpt-4o-mini")

Protocol Compliance

ContextAgent implements ContextEngineerProtocol:
from praisonaiagents.agent import ContextEngineerProtocol

# Check protocol compliance
assert isinstance(agent, ContextEngineerProtocol)

GitHub Analysis

# Analyze GitHub repository
result = agent.start("https://github.com/user/repo Goal: Add authentication")

Multi-Agent Workflow

from praisonaiagents import Agent, Task, Agents, create_context_agent

# Create context engineer
context_engineer = create_context_agent(llm="gpt-4o-mini")

# Analyze codebase
analysis = context_engineer.analyze_codebase_patterns("/path/to/project")

# Create implementation agent with context
developer = Agent(
    name="Developer",
    instructions=f"""
    Implement features following these patterns:
    {analysis}
    """
)

# Create workflow
agents = Agents(agents=[developer], tasks=[...])

Output Directory

Context Engineering outputs are saved to .praison/prp/:
.praison/prp/
├── agent_responses/      # Individual agent responses
├── markdown_outputs/     # Formatted markdown reports
├── debug_logs/           # Debug logs (if enabled)
└── final_results/        # Final PRP and blueprints

Context Engineering vs Context Window Management

ContextAgent (Context Engineering)context=ContextConfig (Context Window)
Codebase analysisToken budgeting
PRP generationAuto-compaction
Pattern extractionSession tracking
Implementation blueprintsMulti-memory aggregation
Validation frameworksOverflow detection

Next Steps