Context Engineering Agent
AI-powered codebase analysis and PRP (Product Requirements Prompt) generation for first-try implementation success
Analyse a codebase and generate a Product Requirements Prompt (PRP) for first-try implementation success with the ContextAgent.
from praisonaiagents import create_context_agent
agent = create_context_agent(llm="gpt-4o-mini", name="Context Engineering Specialist")
analysis = agent.analyze_codebase("/path/to/project")
prp = agent.generate_prp(feature_request="Add user authentication with JWT", context_analysis=analysis)The ContextAgent is a specialized agent for Context Engineering – comprehensive codebase analysis and Product Requirements Prompt (PRP) generation.
Quick Start
- Simple Usage
Create the agent and analyse a project.
python from praisonaiagents import create_context_agent agent = create_context_agent( llm="gpt-4o-mini", name="Context Engineering Specialist", ) analysis = agent.analyze_codebase("/path/to/project") - With PRP Generation
Turn a feature request into an implementation prompt.
python from praisonaiagents import create_context_agent agent = create_context_agent(llm="gpt-4o-mini") analysis = agent.analyze_codebase("/path/to/project") prp = agent.generate_prp( feature_request="Add user authentication with JWT", context_analysis=analysis, ) blueprint = agent.create_implementation_blueprint("JWT auth", analysis)
How It Works
Key Features
| Feature | Description |
|---|---|
| Codebase Analysis | Analyze project structure, patterns, conventions |
| AST Analysis | Extract classes, functions, imports from Python |
| Pattern Extraction | Identify code patterns and architecture |
| PRP Generation | Create comprehensive implementation guidance |
| Validation Framework | Define success criteria and quality gates |
| Implementation Blueprint | Step-by-step implementation plan |
| GitHub Integration | Analyze 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, AgentTeam, create_context_agent
# Create context engineer
context_engineer = create_context_agent(llm="gpt-4o-mini")
# Analyze codebase
analysis = context_engineer.analyze_codebase("/path/to/project")
# Create implementation agent with context
developer = Agent(
name="Developer",
instructions=f"""
Implement features following these patterns:
{analysis}
"""
)
# Create workflow
agents = AgentTeam(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 blueprintsContext Engineering vs Context Window Management
| ContextAgent (Context Engineering) | context=ContextConfig (Context Window) |
|---|---|
| Codebase analysis | Token budgeting |
| PRP generation | Auto-compaction |
| Pattern extraction | Session tracking |
| Implementation blueprints | Multi-memory aggregation |
| Validation frameworks | Overflow detection |
Best Practices
Analyse once, reuse the analysis
analyze_codebase is the expensive step. Cache its result and pass it into generate_prp and create_implementation_blueprint rather than re-scanning for each call.
Scope file patterns to what matters
Pass file_patterns=["*.py"] (or your language) so the agent focuses on relevant source instead of walking test fixtures and generated files.
Feed the PRP to an implementation agent
The generated PRP is designed to prime another agent. Hand it to a Developer agent’s instructions for higher first-try success.
Don't confuse it with ContextConfig
This agent engineers implementation context. For token budgeting and compaction inside a run, use context=ContextConfig() instead — they solve different problems.