Files
tatlock/AGENTS.md
T
jpmschweitzerandClaude Opus 4.5 4c6ac89808 feat: add Phase F.1 memory infrastructure
Add multi-tenancy support and memory storage infrastructure:

- Add ContextVar-based request context (src/core/context.py)
  - Async-safe user/conversation tracking via contextvars
  - RequestContext manager for clean setup/teardown
  - get_user(), get_conversation_id() helpers

- Add multi-tenancy utilities (src/core/multi_tenancy.py)
  - User ID sanitization for collection/key names
  - get_memory_collection_name(), get_session_key() helpers

- Add Ollama embedding client (src/core/embeddings.py)
  - nomic-embed-text model (768 dimensions)
  - embed(), embed_batch(), health_check() methods

- Add Qdrant client wrapper (src/core/qdrant.py)
  - Per-user collection pattern: memories_{user}
  - upsert_memory(), search_memories(), delete_memory()
  - Type-based filtering support

- Add Redis memory cache (src/core/memory_cache.py)
  - Session context with 24h TTL
  - Recent entities tracking
  - Separate from benchmarks (db=2)

- Update config with memory settings
  - QDRANT_HOST, QDRANT_PORT, QDRANT_EMBEDDING_DIM
  - OLLAMA_EMBEDDING_MODEL
  - REDIS_MEMORY_DB, REDIS_MEMORY_TTL_HOURS

- Add user field to ResponseRequest (OpenAI standard)
- Set context in router, reset in finally block
- Update librarian client to use get_user() (12 methods)

All 333 unit tests pass.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-13 17:27:51 +01:00

2.6 KiB

LLM Agent Instructions

This document contains instructions and documentation references for AI assistants working with this codebase.

📖 Important: Before working on this project, read PHILOSOPHY.md to understand the system vision, architectural patterns, and design goals. All development should work towards realizing those patterns.

AGENTS.md

Start every session by reading this file. This file outlines the operational protocols, coding standards, and architectural decisions for this FastAPI project.

1. Agent Operational Protocols

🧠 Work Patterns (Plan-Act-Reflect)

  • Plan: Before writing code, briefly outline your plan. Identify which files you will touch and what the side effects might be.
  • Act: Execute the changes in small, atomic steps.
  • Reflect: After coding, verify your work. Did you break existing tests? Did you add new tests?

🌐 Internal Service Access

  • git.schweitz.net: Access via http://localhost:3002 (direct Gitea) to bypass Authentik SSO
    • Example: curl http://localhost:3002/jpmschweitzer/library-desk/raw/branch/main/README.md
    • Public repos are readable without authentication
    • Related repos: library-desk, scheduler

🛡️ Git Discipline

  • NEVER commit to main or master directly. Always create a feature branch: feature/your-feature-name or fix/issue-description.
  • Commit Messages: Use the Conventional Commits format.
    • feat: add user login endpoint
    • fix: resolve database connection timeout
    • refactor: split monolith dependency file
  • Atomic Commits: Keep commits small. One logical change = one commit.

📝 Changelog Maintenance

  • Update CHANGELOG.md with every user-facing change.
  • Format: ## [Unreleased] - YYYY-MM-DD followed by ### Added, ### Changed, or ### Fixed.

2. FastAPI Architecture & Best Practices

Reference: FastAPI Best Practices

📂 Project Structure (Directory-based, NOT File-type based)

Do not group files by type (e.g., one huge routers folder). Group by domain/module inside a src/ directory.

Correct Structure:

src/
├── auth/
│   ├── router.py      # Endpoints
│   ├── schemas.py     # Pydantic models
│   ├── service.py     # Business logic (CRUD, etc.)
│   ├── dependencies.py# Module-specific dependencies
│   └── config.py      # Module-specific settings
├── posts/
│   ├── router.py
│   └── ...
└── main.py            # App entry point