Fast Context

Search codebase for relevant context to enhance agent responses

The --fast-context flag searches your codebase for relevant code and adds it as context to the agent’s prompt.

Quick Start

bash
praisonai "Find authentication code" --fast-context ./src

!Fast Context Demo

Usage

Basic Fast Context

bash
praisonai "Explain how the login function works" --fast-context ./src

Expected Output:

⚡ Fast Context enabled - searching ./src

📂 Found relevant files:
  • src/auth/login.py (95% relevance)
  • src/auth/utils.py (78% relevance)
  • src/models/user.py (65% relevance)

╭─ Agent Info ─────────────────────────────────────────────────────────────────╮
│  👤 Agent: DirectAgent                                                       │
│  Role: Assistant                                                             │
│  📄 Context: 3 files, 245 lines                                             │
╰──────────────────────────────────────────────────────────────────────────────╯

╭────────────────────────────────── Response ──────────────────────────────────╮
│ Based on the codebase, the login function in `src/auth/login.py` works as   │
│ follows:                                                                     │
│                                                                              │
│ 1. **Input Validation**: The function first validates the email format      │
│    using the `validate_email()` helper from `utils.py`                      │
│                                                                              │
│ 2. **User Lookup**: It queries the database using the User model to find    │
│    the user by email                                                         │
│                                                                              │
│ 3. **Password Verification**: Uses bcrypt to compare the hashed password    │
│                                                                              │
│ 4. **Token Generation**: On success, generates a JWT token with user claims │
╰──────────────────────────────────────────────────────────────────────────────╯

Specify Search Path

bash
# Search specific directory
praisonai "How does the API handle errors?" --fast-context ./src/api

# Search from project root
praisonai "Explain the database schema" --fast-context /path/to/project

# Search current directory
praisonai "Find all test files" --fast-context .

Combine with Other Features

bash
# Fast context with metrics
praisonai "Optimize this function" --fast-context ./src --metrics

# Fast context with guardrail
praisonai "Refactor the code" --fast-context ./src --guardrail "Maintain backward compatibility"

# Fast context with planning
praisonai "Add new feature" --fast-context ./src --planning

How It Works

Diagram

Prompt

Fast Context Search

Relevant Files

Context Injection

Agent + Context

Response

  1. Query Analysis: Analyzes your prompt to understand what code is relevant
  2. Codebase Search: Searches the specified directory for matching files
  3. Relevance Ranking: Ranks files by relevance to your query
  4. Context Injection: Adds relevant code snippets to the agent’s context
  5. Enhanced Response: Agent responds with full codebase awareness

Use Cases

Code Explanation

bash
praisonai "Explain how the payment processing works" --fast-context ./src

Bug Investigation

bash
praisonai "Why might the user session expire unexpectedly?" --fast-context ./src/auth

Expected Output:

⚡ Fast Context enabled

📂 Found relevant files:
  • src/auth/session.py
  • src/auth/middleware.py
  • src/config/settings.py

╭────────────────────────────────── Response ──────────────────────────────────╮
│ Based on the code analysis, there are several potential causes for          │
│ unexpected session expiration:                                               │
│                                                                              │
│ 1. **Short Timeout**: In `settings.py`, `SESSION_TIMEOUT` is set to 300     │
│    seconds (5 minutes), which may be too short for some use cases           │
│                                                                              │
│ 2. **Missing Refresh**: The `session.py` doesn't implement token refresh    │
│    on activity, so sessions expire even during active use                   │
│                                                                              │
│ 3. **Race Condition**: In `middleware.py` line 45, there's a potential      │
│    race condition when checking session validity                            │
╰──────────────────────────────────────────────────────────────────────────────╯

Code Review

bash
praisonai "Review the error handling in this codebase" --fast-context ./src

Feature Planning

bash
praisonai "How would I add OAuth support based on the current auth system?" --fast-context ./src/auth

Documentation Generation

bash
praisonai "Generate API documentation for the user endpoints" --fast-context ./src/api/users

Search Configuration

File Types Searched

By default, Fast Context searches common code files:

LanguageExtensions
Python.py
JavaScript.js, .jsx, .ts, .tsx
Go.go
Rust.rs
Java.java
C/C++.c, .cpp, .h, .hpp
Ruby.rb
PHP.php

Ignored Paths

These directories are automatically excluded:

  • node_modules/
  • venv/, .venv/
  • __pycache__/
  • .git/
  • dist/, build/

Best Practices

Performance Tips

ScenarioRecommendation
Large codebaseSearch specific subdirectories
Many files foundRefine your prompt to be more specific
Slow searchExclude unnecessary directories
High token usageLimit search depth or file count

Related