Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ After making code changes, proactively run the full CI/linting pipeline before p
Only report work as complete after all checks pass.

## Project Overview
Lightspeed Core Stack (LCS) is an AI-powered assistant built on FastAPI that provides answers using LLM services, agents, and RAG databases. It integrates with Llama Stack for AI operations.
Lightspeed Core Stack (LCS) is an AI-powered assistant built on FastAPI that provides answers using LLM services, agents, and RAG databases. It integrates with OGX for AI operations.

## Development Environment
- **Python**: Check `pyproject.toml` for supported Python versions
Expand Down Expand Up @@ -60,7 +60,7 @@ src/
│   │   ├── mcp_servers.py # Handler for REST API calls to dynamically manage MCP servers
│   │   ├── metrics.py # Handler for REST API call to provide metrics
│   │   ├── models.py # Handler for REST API call to list available models
│   │   ├── prompts.py # Handler for REST API calls to manage Llama Stack stored prompt templates
│   │   ├── prompts.py # Handler for REST API calls to manage OGX stored prompt templates
│   │   ├── providers.py # Handler for REST API calls to list and retrieve available providers
│   │   ├── query.py # Handler for REST API call to provide answer to query using Response API
│   │   ├── rags.py # Handler for REST API calls to list and retrieve available RAGs
Expand Down Expand Up @@ -106,7 +106,7 @@ src/
│   ├── noop_cache.py # No-operation cache implementation
│   ├── postgres_cache.py # PostgreSQL cache implementation
│   └── sqlite_cache.py # Cache that uses SQLite to store cached values
├── data/ # Built-in default Llama Stack baseline for unified-mode synthesis
├── data/ # Built-in default OGX baseline for unified-mode synthesis
│   └── default_run.yaml # The starting point when a unified `lightspeed-stack.yaml` select default baseline
├── quota/ # Quota limiter and token usage tracking
│   ├── cluster_quota_limiter.py # Simple cluster quota limiter where quota is fixed for the whole cluster
Expand Down Expand Up @@ -173,7 +173,7 @@ src/
│   │   │   └── turn_accumulator.py # Mutable per-turn state for agent response processing
│   │   ├── responses/ # Shared models for the OpenAI-compatible Responses API pipeline
│   │   │   ├── contexts.py # Context objects for the responses endpoint pipeline and streaming query generators.
│   │   │   ├── responses_api_params.py # Request parameter model for Llama Stack responses API calls
│   │   │   ├── responses_api_params.py # Request parameter model for OGX responses API calls
│   │   │   ├── responses_conversation_context.py # Conversation resolution result model for the OpenAI-compatible responses endpoint
│   │   │   └── types.py # Type aliases for OpenAI-compatible Responses API input shapes
│   │   ├── conversation.py # Conversation list rows, metadata, and simplified turn/message shapes for APIs
Expand Down Expand Up @@ -203,10 +203,10 @@ src/
│   │   └── redaction/ # PII redaction capability for Pydantic AI agents
│   │   ├── capability.py # Pydantic AI capability for PII redaction of model messages
│   │   └── core.py # Core redaction logic for PII detection and replacement
│   └── llamastack/ # Pydantic AI provider for Llama Stack
│   ├── _model.py # Custom OpenAI Responses model that works around Llama Stack streaming quirks
│   ├── _provider.py # Llama Stack provider implementation for Pydantic AI
│   └── _transport.py # httpx transport that routes OpenAI-compatible requests through a Llama Stack library client
│   └── llamastack/ # Pydantic AI provider for OGX
│   ├── _model.py # Custom OpenAI Responses model that works around OGX streaming quirks
│   ├── _provider.py # OGX provider implementation for Pydantic AI
│   └── _transport.py # httpx transport that routes OpenAI-compatible requests through an OGX library client
├── telemetry/ # Telemetry module for configuration snapshot collection
│   └── configuration_snapshot.py # Configuration snapshot with PII masking for telemetry
├── utils/ # Utility functions
Expand All @@ -224,21 +224,21 @@ src/
│   ├── degraded_mode.py # Degraded mode state tracking
│   ├── endpoints.py # Utility functions for endpoint handlers
│   ├── json_schema_updater.py # Function to transform a JSON Schema-like dictionary into an OpenAPI-compatible schema
│   ├── llama_stack_version.py # Check if the Llama Stack version is supported by the LCS
│   ├── llama_stack_version.py # Check if the OGX version is supported by the LCS
│   ├── markdown_repair.py # Utilities for repairing truncated markdown content
│   ├── mcp_auth_headers.py # Utilities for resolving MCP server authorization headers
│   ├── mcp_headers.py # MCP headers handling
│   ├── mcp_oauth_probe.py # Probe MCP servers for OAuth and raise 401 with WWW-Authenticate when required
│   ├── models_dumper.py # Function to dump the schema of all data models into OpenAPI-compatible format
│   ├── openapi_schema_dumper.py # Utility function to dump schema with list of models into OpenAPI-compatible JSON format
│   ├── prompts.py # Utility functions for system prompts
│   ├── pydantic_ai_helpers.py # Helpers for running Pydantic AI agents against Llama Stack (Responses API compatibility)
│   ├── pydantic_ai_helpers.py # Helpers for running Pydantic AI agents against OGX (Responses API compatibility)
│   ├── query.py # Utility functions for working with queries
│   ├── quota_utils.py # Quota handling helper functions
│   ├── reranker.py # Reranker utilities for RAG chunk reranking
│   ├── responses.py # Utility functions for processing Responses API output
│   ├── rh_identity.py # Utility functions for extracting RH Identity context for telemetry
│   ├── shields.py # Utility functions for working with Llama Stack shields
│   ├── shields.py # Utility functions for working with OGX shields
│   ├── streaming_sse.py # SSE formatting helpers for streaming query responses
│   ├── stream_interrupts.py # Stream interrupt registry and persistence utilities
│   ├── suid.py # Session ID utility functions
Expand All @@ -250,9 +250,9 @@ src/
│   └── vector_search.py # Vector search utilities for query endpoints
├── sentry.py # Sentry error tracking initialization and configuration
├── lightspeed_stack.py # Entry point to the Lightspeed Core Stack REST API service
├── llama_stack_configuration.py # Llama Stack configuration enrichment and synthesis
├── llama_stack_configuration.py # OGX configuration enrichment and synthesis
├── log.py # Log utilities
├── client.py # Llama Stack client wrapper (Singleton)
├── client.py # OGX client wrapper (Singleton)
├── configuration.py # Config management (Singleton)
├── constants.py # Shared (final) constants
└── version.py # Service version that is read by project manager tools
Expand All @@ -263,7 +263,7 @@ src/
#### Imports & Dependencies
- Use absolute imports for internal modules: `from authentication import get_auth_dependency`
- FastAPI dependencies: `from fastapi import APIRouter, HTTPException, Request, status, Depends`
- Llama Stack imports: `from ogx_client import AsyncOgxClient`
- OGX imports: `from ogx_client import AsyncOgxClient`
- **ALWAYS** check `pyproject.toml` for existing dependencies before adding new ones
- **ALWAYS** verify current library versions in `pyproject.toml` rather than assuming versions
- Check `constants.py` for shared constants before defining new ones
Expand Down Expand Up @@ -304,7 +304,7 @@ src/
- **Async Functions**: Use `async def` for I/O operations and external API calls
- **Error Handling**:
- Use FastAPI `HTTPException` with appropriate status codes for API endpoints
- Handle `APIConnectionError` from Llama Stack
- Handle `APIConnectionError` from OGX

#### Logging Standards
- Use `from log import get_logger` and module logger pattern: `logger = get_logger(__name__)`
Expand Down Expand Up @@ -405,7 +405,7 @@ uv run make test-e2e # End-to-end tests
## Key Dependencies
**IMPORTANT**: Always check `pyproject.toml` for current versions rather than relying on this list:
- **FastAPI**: Web framework
- **Llama Stack**: AI integration
- **OGX**: AI integration
- **Pydantic**: Data validation/serialization
- **SQLAlchemy**: Database ORM
- **Kubernetes**: K8s auth integration
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ Use `async def` for I/O operations and external API calls
#### Error handling

- Use FastAPI `HTTPException` with appropriate status codes for API endpoints
- Handle `APIConnectionError` from Llama Stack where appropriate
- Handle `APIConnectionError` from OGX where appropriate

### Formatting rules

Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ run: start-llama-stack-container ## Run the service locally with dependent servi
@trap 'echo ""; echo "Stopping services..."; $(MAKE) stop-llama-stack-container' EXIT INT TERM; \
$(MAKE) run-stack

build-llama-stack-image: remove-llama-stack-container ## Build llama-stack container image
build-llama-stack-image: remove-llama-stack-container ## Build OGX container image
@echo "Building llama-stack container image..."
@if [ -z "$(CONTAINER_RUNTIME)" ]; then \
echo "ERROR: No container runtime found. Install podman or docker."; \
exit 1; \
fi
$(CONTAINER_RUNTIME) build -f deploy/llama-stack/test.containerfile -t $(LLAMA_STACK_IMAGE) .

stop-llama-stack-container: ## Gracefully stop llama-stack container
stop-llama-stack-container: ## Gracefully stop OGX container
@if [ -n "$(CONTAINER_RUNTIME)" ] && $(CONTAINER_RUNTIME) inspect $(LLAMA_STACK_CONTAINER_NAME) >/dev/null 2>&1; then \
echo "Stopping llama-stack container (timeout: 10s)..."; \
if $(CONTAINER_RUNTIME) stop -t 10 $(LLAMA_STACK_CONTAINER_NAME) 2>/dev/null; then \
Expand All @@ -62,7 +62,7 @@ stop-llama-stack-container: ## Gracefully stop llama-stack container
fi; \
fi

remove-llama-stack-container: ## Remove llama-stack container (saves logs first)
remove-llama-stack-container: ## Remove OGX container (saves logs first)
@if [ -n "$(CONTAINER_RUNTIME)" ] && $(CONTAINER_RUNTIME) inspect $(LLAMA_STACK_CONTAINER_NAME) >/dev/null 2>&1; then \
echo "Saving container logs before removal..."; \
$(CONTAINER_RUNTIME) logs $(LLAMA_STACK_CONTAINER_NAME) > /tmp/llama-stack-last-run.log 2>&1 || true; \
Expand All @@ -71,7 +71,7 @@ remove-llama-stack-container: ## Remove llama-stack container (saves logs first)
echo "✓ Container removed (logs saved to /tmp/llama-stack-last-run.log)"; \
fi

start-llama-stack-container: build-llama-stack-image ## Start llama-stack container
start-llama-stack-container: build-llama-stack-image ## Start OGX container
@echo "Starting llama-stack container..."
$(CONTAINER_RUNTIME) run -d \
--name $(LLAMA_STACK_CONTAINER_NAME) \
Expand Down Expand Up @@ -120,7 +120,7 @@ start-llama-stack-container: build-llama-stack-image ## Start llama-stack contai
$(LLAMA_STACK_IMAGE)
@$(MAKE) wait-for-llama-stack-health

wait-for-llama-stack-health: ## Wait for llama-stack container to be healthy
wait-for-llama-stack-health: ## Wait for OGX container to be healthy
@echo "Waiting for llama-stack container to be healthy..."
@for i in {1..30}; do \
STATUS=$$($(CONTAINER_RUNTIME) inspect --format='{{.State.Health.Status}}' $(LLAMA_STACK_CONTAINER_NAME) 2>/dev/null || echo "no-healthcheck"); \
Expand All @@ -142,7 +142,7 @@ clean-llama-stack: remove-llama-stack-container ## Remove container and image
$(CONTAINER_RUNTIME) rmi $(LLAMA_STACK_IMAGE); \
fi

run-llama-stack: ## Start Llama Stack with enriched config (for local service mode)
run-llama-stack: ## Start OGX with enriched config (for local service mode)
uv run src/llama_stack_configuration.py -c $(CONFIG) -i $(LLAMA_STACK_CONFIG) -o $(LLAMA_STACK_CONFIG) && \
uv run ogx stack run $(LLAMA_STACK_CONFIG)

Expand Down
Loading
Loading