Skip to main content

ContextAgent Module

The ContextAgent class implements advanced Context Engineering principles for AI coding assistants, following the PRD (Product Requirements Document) methodology.

Key Features

  • 10x better than prompt engineering
  • 100x better than vibe coding
  • Comprehensive context generation for first-try implementation success
  • Systematic codebase analysis with modern tools
  • PRP (Product Requirements Prompt) generation
  • Validation loops and quality gates
  • Saves every agent response for complete traceability

Import

from praisonaiagents import ContextAgent

Quick Example

from praisonaiagents import ContextAgent

agent = ContextAgent(
    project_path="/path/to/your/project",
    auto_analyze=True
)

# Generate comprehensive context for a feature
result = agent.analyze_and_generate_prp(
    feature_description="Add user authentication with OAuth2"
)

print(result.implementation_blueprint)

Constructor

ContextAgent()

Creates a new ContextAgent instance. Parameters:
ParameterTypeDefaultDescription
namestr"Context Engineering Specialist"Agent name
rolestr"Expert Context Engineer..."Agent role
goalstr"Perform comprehensive codebase analysis..."Agent goal
backstorystrAuto-generatedAgent backstory
instructionsstrNoneCustom instructions
llmstrNoneLLM model to use
toolslistAuto-configuredTools for analysis
project_pathstrNonePath to project to analyze
auto_analyzeboolTrueAuto-analyze on init

Phases

The ContextAgent follows a systematic 5-phase approach:

Phase 1: Deep Codebase Analysis

Using gitingest, AST analysis, and other tools to understand the codebase structure.

Phase 2: Pattern Extraction and Documentation

Identifying coding patterns, conventions, and architectural decisions.

Phase 3: Comprehensive PRP Generation

Creating detailed Product Requirements Prompts for implementation.

Phase 4: Validation Framework Creation

Building validation criteria and quality gates.

Phase 5: Implementation Blueprint Generation

Generating step-by-step implementation guidance.

Methods

analyze_and_generate_prp(feature_description)

Performs full context engineering workflow. Parameters:
  • feature_description (str): Description of the feature to implement
Returns: ContextResult - Contains analysis, PRP, and blueprint

analyze_codebase()

Analyzes the project codebase. Returns: dict - Analysis results

generate_prp(feature_description)

Generates a Product Requirements Prompt. Parameters:
  • feature_description (str): Feature description
Returns: str - Generated PRP

generate_implementation_blueprint()

Generates implementation guidance. Returns: dict - Implementation blueprint

Attributes

AttributeTypeDescription
project_pathstrPath to the project
analysis_resultsdictCodebase analysis results
prp_resultsdictGenerated PRPs
context_documentationdictContext documentation
implementation_blueprintdictImplementation guidance
agent_interactionslistAll agent interactions (for traceability)

Output Directory

Results are saved to .praison/prp/ in the project directory for complete traceability.

Example: Full Workflow

from praisonaiagents import ContextAgent

# Initialize with project
agent = ContextAgent(
    project_path="/path/to/my-app",
    auto_analyze=True
)

# Analyze codebase
analysis = agent.analyze_codebase()
print(f"Found {len(analysis['files'])} files")
print(f"Patterns: {analysis['patterns']}")

# Generate PRP for a feature
prp = agent.generate_prp(
    "Add real-time notifications using WebSockets"
)
print(prp)

# Get implementation blueprint
blueprint = agent.generate_implementation_blueprint()
for step in blueprint['steps']:
    print(f"- {step['description']}")