This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
- Active the venv in .venv at the start of the session
pytest- Run all testspytest tests/core/- Run core tests onlypytest tests/services/- Run service tests onlypytest tests/core/test_specific_file.py- Run specific test filepytest -k "test_name"- Run specific test by name
black .- Format code with Blackisort .- Sort importsflake8 .- Lint codemypy src/- Type check source codeautoflake8 --in-place --recursive .- Remove unused imports- Remember to run linter checks and tests after your changes are done and fix any issues that arise
pip install -e .- Install in development modepython -m build- Build distribution packages
Praga Core is a framework for building document retrieval toolkits and agents for LLM applications, implementing LLMRP (LLM Retrieval Protocol) for standardized document retrieval over HTTP.
-
Context Layer (
context.py,global_context.py,action_executor.py)ServerContext: Main context inheriting fromActionExecutorMixinActionExecutorMixin: Mixin providing action registration and execution@actiondecorator: Transforms Page signatures to PageURI signatures- Global context management for service-wide state
-
Agent Layer (
agents/)ReactAgent: ReAct methodology implementation for document retrievalRetrieverToolkit: Tool collection for document operations- Template-based agent responses with JSON parsing
- Integration with OpenAI API for LLM interactions
-
Page Cache System (
page_cache/)PageCache: Async SQLite-based caching with separated concernsPageStorage: Core CRUD operationsPageRegistry: Type registration and table managementPageValidator: Validation logicProvenanceManager: Relationship tracking between pages
-
Integration Layer (
integrations/)- MCP (Model Context Protocol) server implementation
- FastMCP integration for exposing context functionality
- Action and search tool descriptions
-
Service Layer (
service.py,pragweb/)- Base
Serviceclass for external API integrations - Google API services (Calendar, Docs, Gmail, People)
- Slack integration stub
- Secrets management
- Base
- Async-first architecture: All core operations are async
- Mixin-based composition:
ActionExecutorMixinavoids circular dependencies - Signature transformation: Actions defined with Page params, exposed as PageURI API
- Type safety: Comprehensive type hints and mypy checking
- Separation of concerns: Clear component boundaries in PageCache
- Protocol-based design: LLMRP for standardized retrieval
The action system uses a sophisticated signature transformation pattern:
-
Definition: Actions are defined with
Pageparameters:@context.action() def mark_email_read(email: EmailPage) -> bool: email.read = True return True
-
Registration: The
@actiondecorator creates wrapper functions that:- Accept
PageURIparameters instead ofPageparameters - Use
context.get_pages()for bulk async page retrieval - Call the original function with resolved
Pageobjects
- Accept
-
Invocation:
context.invoke_action()only acceptsPageURIarguments:result = await context.invoke_action("mark_email_read", {"email": page_uri})
-
API Boundary: External API strictly enforces PageURI-only interface, rejecting Page objects with helpful error messages
This design ensures:
- Clean separation between external API (PageURI) and internal logic (Page)
- Efficient bulk page retrieval for performance
- Type safety through wrapper function signature transformation
- Async consistency throughout the codebase
- Uses pytest with asyncio mode enabled
- Test files follow
test_*.pypattern - Async tests supported by default
- Comprehensive coverage of core and service layers
- Black formatter with 88-character line length
- isort for import sorting with Black profile
- Strict mypy configuration with comprehensive type checking
- Flake8 linting with extended rules
- Python 3.11+ required