Skip to main content

Context Module

The context module provides fast context retrieval capabilities for codebase understanding, including the FastContext class for intelligent code search.

Installation

pip install praisonaiagents

Quick Start

from praisonaiagents import FastContext

# Create fast context instance
context = FastContext(workspace_dir="./my_project")

# Search for relevant code
result = context.search("authentication logic")
print(result.files)
print(result.snippets)

Classes

FastContext

Fast codebase context retrieval.
from praisonaiagents import FastContext

context = FastContext(
    workspace_dir="./project",
    max_results=10
)

Methods

MethodDescription
search(query)Search for relevant code
get_file(path)Get file contents
get_symbols(path)Get symbols in file

FastContextResult

Result from a context search.
from praisonaiagents import FastContextResult

result = context.search("database connection")
result.files       # Matching files
result.snippets    # Code snippets
result.relevance   # Relevance scores

FileMatch

A matched file from search.
from praisonaiagents import FileMatch

match.path        # File path
match.score       # Relevance score
match.lines       # Matching line ranges

LineRange

A range of lines in a file.
from praisonaiagents import LineRange

range.start    # Start line
range.end      # End line
range.content  # Line content

Usage Examples

from praisonaiagents import FastContext

context = FastContext(workspace_dir="./src")
result = context.search("user authentication")

for file in result.files:
    print(f"{file.path}: {file.score}")

With Agent

from praisonaiagents import Agent, FastContext

context = FastContext(workspace_dir="./project")

agent = Agent(
    name="CodeAssistant",
    context=context
)

# Agent can search codebase for context