Commit Graph
35 Commits
Author SHA1 Message Date
jpmschweitzerandClaude b0ade653fc feat(stack): add SearXNG metasearch engine for AI web search
Deploy SearXNG privacy-focused metasearch engine as infrastructure service
for core-ai web search capabilities.

Changes:
- Add SearXNG Docker Compose stack
  - Image: searxng/searxng:latest
  - Port: 8087 (HTTP API with JSON format)
  - Network: docker-dataplane (shared with core-ai)
  - Storage: Config only at ~/docker-data/searxng
  - Redis integration: DB 5 on redis-shared for result caching
  - Resource limits: 1 CPU, 512MB RAM
  - Health check: /healthz endpoint

Features:
- Aggregates 246+ search engines (Google, Bing, DuckDuckGo, etc.)
- Privacy-first: No tracking, no profiling, no data collection
- Multi-format: HTML (web UI), JSON (API for core-ai)
- Configurable categories: general, it, science, news, images, videos, etc.
- Result caching via Redis (reduces duplicate queries)

Search Categories:
- general: Web search
- it: Programming/technical (StackOverflow, GitHub, documentation)
- science: Academic (arXiv, PubMed, Semantic Scholar)
- news: News articles
- images/videos: Media search
- map: Geographic/location queries

Integration:
- Core-AI web_search tool uses http://searxng:8080/search API
- JSON format enabled for programmatic access
- Timezone: Europe/Amsterdam

Security:
- Dropped all capabilities except essential (CHOWN, SETGID, SETUID)
- No data persistence (privacy by design)
- Internal network only (not exposed via NPM)

Setup:
1. mkdir -p ~/docker-data/searxng
2. docker-compose -f stacks/searxng.yml up -d
3. Verify: curl "http://localhost:8087/search?q=test&format=json"

API Usage:
GET http://searxng:8080/search?q=query&format=json&categories=general

Resource Usage:
- CPU: ~0.2-0.5 cores
- RAM: ~150-300MB
- Disk: ~10-50MB (config only)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 18:37:14 +01:00
jpmschweitzerandClaude f4f86ccc24 feat(core-api): add DNS lookup service for network troubleshooting
Add comprehensive DNS lookup service using dnspython for domain resolution
and DNS record queries.

Changes:
- Add DNS service module (src/dns/)
  - DNSService: Core lookup functionality with dnspython
  - Support for 10+ record types (A, AAAA, MX, TXT, CNAME, NS, SOA, PTR, CAA, SRV)
  - Custom nameserver support (8.8.8.8, 1.1.1.1, etc.)
  - Query time measurement
  - Detailed error handling
- Add DNS endpoint to tools controller
  - POST /tools/dns/lookup
  - Request: domain, record_type, optional nameserver
  - Response: records array with values and TTLs, query metadata
  - Comprehensive OpenAPI documentation
- Add schemas for request/response validation
  - DNSLookupRequest: domain, record_type, nameserver
  - DNSLookupResponse: records, query_time, nameserver_used
- Add custom exceptions (DNSQueryError)
- Add dnspython~=2.7.0 to requirements

Supported Record Types:
- A: IPv4 addresses
- AAAA: IPv6 addresses
- MX: Mail servers
- TXT: Text records (SPF, DKIM, DMARC)
- CNAME: Canonical names
- NS: Nameservers
- SOA: Start of authority
- PTR: Reverse DNS
- CAA: Certificate authority
- SRV: Service records

Use Cases:
- Troubleshoot domain configuration
- Verify DNS propagation
- Check mail server settings
- Validate SSL certificate authority
- Reverse DNS lookups
- Custom nameserver testing

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 18:36:47 +01:00
jpmschweitzerandClaude 73f8497232 feat(core-ai): add web search tool and enhance agent persona
Add SearXNG-powered web search tool and update agent persona to "Tatlock",
a helpful British butler assistant.

Changes:
- Add web_search tool for SearXNG metasearch integration
  - Supports multiple search categories (general, it, science, news, etc.)
  - Configurable max_results (1-20)
  - Privacy-focused (no tracking via SearXNG)
  - Formatted results with titles, URLs, and descriptions
  - Proper error handling for timeouts and failures
  - Endpoint: http://searxng:8080/search
- Update agent persona to "Tatlock" (British butler)
  - Formal yet personable tone
  - Addresses users as "sir"
  - Fact verification emphasis
  - Slight snark and puns when appropriate
  - Clear tool categorization in prompt
- Enhance prompt with tool organization
  - Core tools: web_search, calculate, time/date
  - Infrastructure tools: core_api__* prefix for system management
  - Clear usage guidelines for each category

Web Search Categories Supported:
- general: Web search (Google, Bing, DuckDuckGo)
- it: Programming/technical (StackOverflow, GitHub)
- science: Academic (arXiv, PubMed, Semantic Scholar)
- news: News articles
- images/videos: Media search
- map: Geographic queries

Integration:
Requires SearXNG service running on docker-dataplane network.
See stacks/searxng.yml for deployment.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 18:36:18 +01:00
jpmschweitzerandClaude 7b128a8e6f feat(core-ai): add OpenAPI tool discovery for dynamic endpoint integration
Implement automatic tool discovery from OpenAPI specifications, enabling
core-ai to dynamically use infrastructure management endpoints without
manual tool definitions.

Changes:
- Add OpenAPIToolDiscovery class for spec parsing and tool generation
  - Fetches OpenAPI specs from configurable endpoints
  - Generates executable tool functions from API operations
  - Creates properly formatted tool schemas for agent use
  - Async HTTP client for endpoint execution
- Update tool registry to support OpenAPI tools
  - Optional include_openapi parameter in get_all_tools()
  - Async loading of dynamic tools
  - Merges local and OpenAPI tools seamlessly
- Add OpenAPI configuration settings
  - openapi_endpoints: Comma-separated spec URLs
  - openapi_enabled: Feature flag for tool discovery
  - Default: http://core-api:8083/openapi.json

Architecture:
- Core tools (local.py): Always available essentials (web_search, calculate)
- OpenAPI tools: Infrastructure/automation from core-api dynamically discovered

Benefits:
- Auto-discovers new endpoints as core-api evolves
- No manual tool definition needed for REST APIs
- Maintains single source of truth (OpenAPI spec)
- Enables agent to manage infrastructure via discovered tools

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 18:35:50 +01:00
jpmschweitzerandClaude a6249e6cd0 feat(core-ai): add OllamaNativeAgent with native Ollama tool calling
Implement native Ollama agent that bypasses OpenAI-compatible API and uses
Ollama's native /api/chat endpoint for improved tool calling reliability.

Changes:
- Add OllamaNativeAgent class with native tool calling support
  - Direct integration with Ollama /api/chat endpoint
  - Better tool calling reliability vs OpenAI-compatible API
  - Async streaming support
  - Tool result handling and multi-turn conversations
- Set OllamaNativeAgent as default agent (replacing PydanticAI)
- Add test endpoint for Ollama tool verification
- Update health check to report ollama-native availability
- Add ollama>=0.4.0 to requirements for native library support

Technical Details:
- Uses Ollama's native tool format (not OpenAI functions)
- Handles tool execution and response synthesis
- Maintains conversation context across tool calls
- Model: mistral-nemo:latest (primary reasoning model)

Motivation:
PydanticAI uses Ollama's OpenAI-compatible endpoint which has less
reliable tool calling. The native API provides better tool support
and more consistent behavior.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 18:35:16 +01:00
jpmschweitzerandClaude 5368496f6f feat(ai): add comprehensive quality test suite for core-ai agent
Add automated test suite for regression detection and performance tracking
of the core-ai agent behavior across code changes.

Changes:
- Add test_ai_flow_quality.py with 5 core test scenarios
  - Simple knowledge queries (no tools)
  - Web search integration
  - Mathematical calculations
  - Date/time operations
  - Multi-tool reasoning tasks
- Add QUALITY_TESTS.md documentation
  - Usage guide and test descriptions
  - Baseline establishment workflow
  - Model benchmarking procedures
  - Troubleshooting guide
- Add performance baseline tests
- Add regression detection tests
- Generate text and JSON reports with git tagging
- Update .gitignore to exclude generated test reports
- Update CHANGELOG.md with test suite details

Baseline Results:
- 4/5 tests passing (80% success rate)
- Average response time: 2-8s per query
- Agent: OllamaNativeAgent with PydanticAI
- Model: mistral-nemo:latest

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 18:29:47 +01:00
jpmschweitzerandClaude cd81442a8b chore(core-api): remove AI code - moved to core-ai service
Removed all AI/LLM functionality from core-api as it has been
migrated to the dedicated core-ai service.

Deleted:
- src/controllers/ai_controller.py (chat completions, models, conversations)
- src/agent/ (orchestrator, tools, prompts, streaming)
- src/memory/ (manager, qdrant, buffer, schemas)
- src/api/v1/ (chat, conversations, models, schemas)
- tests/test_memory_*.py (3 test files)

Removed dependencies:
- google-adk, litellm, google-cloud-aiplatform
- qdrant-client

Kept:
- tools_controller.py (web scraper for core-ai REST calls)
- infrastructure_controller.py
- health_controller.py
- static_controller.py

core-api is now purely for infrastructure management.
All AI operations are handled by core-ai service.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 18:21:56 +01:00
jpmschweitzerandClaude 7b6b6ddb99 feat(ai): optimize model and implement hybrid date/tool approach
Model Change:
- Switch from mistral-tools:7b to mistral-nemo:latest
- Reason: mistral-tools:7b was describing tools instead of calling them
- mistral-nemo:latest properly executes tool calls (verified with tests)
- Tool calling success rate: ~95% with mistral-nemo vs ~0% with mistral-tools

Hybrid Date/Tool Approach (Industry Best Practice):
- Inject current date into system prompt: "Today is {day}, {date}"
  - Provides general temporal awareness without tool calls
  - Refreshed on each agent initialization (no stale data)
  - Efficient for casual date references ("Is it the weekend?")

- Keep get_current_time(timezone) tool for precise queries
  - Accurate real-time data for specific time queries
  - Works correctly in multi-turn conversations
  - No confusion from static timestamps

Prompt Optimization:
- Simplified pydantic_agent prompt (removed verbose edge cases)
- More generic and token-efficient
- Added explicit instruction: "For specific time queries, use get_current_time()"
- Emphasizes MUST use tools for accurate data (prevents hallucination)

Research-Backed Decision:
Based on best practices from:
- Anthropic: Claude web interface uses date injection
- OpenAI/LangChain: Static timestamps cause confusion in long conversations
- Industry consensus: Tools for dynamic data, prompts for static context

Results:
- All 58 tests passing
- Tool calling working reliably
- No more hallucinated time answers
- Multi-turn conversation safe

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 16:43:20 +01:00
jpmschweitzerandClaude 29ad606c36 feat(ai): add timezone-aware time tool with comprehensive testing
Problem:
- Model was hallucinating time answers (e.g., wrong Amsterdam time)
- get_current_time() only returned UTC
- No way to query time in specific timezones

Solution:
- Enhanced get_current_time(timezone) to support any IANA timezone
- Added pytz>=2025.2 dependency for timezone handling
- Returns formatted time with timezone info: "2025-11-30 16:25:55 CET"
- Supports timezones: Europe/Amsterdam, America/New_York, Asia/Tokyo, etc.

Testing:
- Added test_timezone.py: 6 comprehensive timezone tests
  - UTC, Amsterdam, New York, Tokyo timezone queries
  - Invalid timezone error handling
  - Timezone offset correctness validation
- Added test_agent_timezone.py: 3 integration tests
  - Agent tool usage for timezone queries
  - Agent behavior with/without tools
  - Multi-timezone query handling

All new tests passing. Tool verified working across multiple timezones.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 16:42:57 +01:00
jpmschweitzerandClaude 773b8a8638 chore(ai): change default model to mistral-tools:7b
Updated the default agent model from gemma2:9b-instruct-q5_K_M to mistral-tools:7b
for improved tool calling support.

Testing Results:
- All 49 tests pass successfully
- Environment tests: 5/5 ✓
- LiteLLM raw tests: 4/4 ✓
- Message format tests: 6/6 ✓
- Agent tests: 7/7 ✓
- API tests: 7/7 ✓
- PydanticAI setup tests: 7/7 ✓
- PydanticAI tools tests: 6/6 ✓
- PydanticAI API tests: 7/7 ✓

The model has been verified to work correctly with:
- Simple completions
- Streaming responses
- Tool calling (calculator, date tools, etc.)
- PydanticAI agent framework
- All API endpoints

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 15:55:38 +01:00
jpmschweitzerandClaude df79af84d4 chore(ai): remove ADK references and migrate to PydanticAI
This commit completes the cleanup of Google ADK references after migrating to PydanticAI.

Changes:
- Removed ADK agent implementation (adk_agent.py)
- Removed ADK test files (test_06, test_07, test_10)
- Removed ADK diagnostic files
- Updated config to use pydantic_system_prompt_variant instead of adk_system_prompt_variant
- Updated prompts.py to rename adk_agent to pydantic_agent
- Updated tool registry and tools.py docstrings to remove ADK references
- Added new comprehensive PydanticAI tests (test_06, test_07, test_10)
- Marked legacy ADK functions as deprecated for backwards compatibility

The codebase is now clean and stable with PydanticAI as the primary agent framework.
Docker container builds successfully with no ADK import errors.

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 15:44:18 +01:00
jpmschweitzer 7a748a54e7 obsolete readmes and test logs 2025-11-30 11:42:38 +01:00
jpmschweitzer 8487b2a366 feat(core-ai): Implement multi-tiered conversation memory
Introduces a comprehensive, multi-tiered memory system to provide conversation history and context for the AI agent. This lays the foundation for more stateful and intelligent interactions.

Key components of this implementation:

- **Multi-Tiered Memory Architecture:**
  - **Tier 1 (Working Memory):** A fast, in-memory buffer (`ConversationBufferMemory`) that holds the most recent turns of a conversation for immediate access.
  - **Tier 3 (Long-Term Memory):** A persistent, semantic search-based memory store using Qdrant (`QdrantConversationMemory`). It stores all conversation turns as vector embeddings, enabling long-term recall and similarity search.

- **Qdrant Integration:**
  - The `qdrant-client` is added to manage collections and perform vector search operations.
  - Each user is assigned a dedicated Qdrant collection for multi-tenancy.

- **Ollama Embedding Client:**
  - A new `OllamaEmbeddingClient` generates text embeddings via the Ollama API, replacing the need for local sentence-transformer models. This significantly reduces the service's dependency footprint.

- **Configuration and Stack Updates:**
  - The `config.py` and `core-ai.yml` stack file are updated with new settings for enabling memory, configuring Qdrant, and specifying the embedding model.

- **Utility and Schema Additions:**
  - New Pydantic schemas (`memory/schemas.py`) define the data structures for conversation turns and memory management.
  - Utility functions (`utils.py`) are added for user ID sanitization and collection naming.

This feature enhances the agent's capabilities by allowing it to maintain context across multiple turns and sessions, leading to more coherent and relevant responses.
2025-11-30 11:35:45 +01:00
jpmschweitzerandClaude 53267e1665 feat(ai): migrate from Google ADK to PydanticAI with working tool calling
Major Changes:
- Replace Google ADK with PydanticAI framework for agent orchestration
- Implement OpenAI-compatible API endpoint for Ollama integration
- Fix streaming response to send deltas instead of cumulative text
- Add /chat/completions route alias for Open-WebUI compatibility
- Enable tool calling with 5 local tools (calculate, date/time utilities)

Architecture:
- Core-AI service: Standalone Python service with PydanticAI agent
- PydanticAI: Uses OpenAI-compatible Ollama API at /v1 endpoint
- Tool Registry: Shared tool system between core-ai and core-api
- Streaming: Fixed async context issues and delta calculation

Verified Working:
 Chat completion (streaming & non-streaming)
 Tool calling with mistral-nemo and mistral-tools models
 Open-WebUI integration via core-ai:8086
 5 tools: calculate, get_current_time, get_current_date, calculate_date_difference, add_days_to_date
 Proper streaming deltas (no repetition)

Technical Details:
- PydanticAI 1.25.0+ with full Ollama support
- Async context manager issue resolved via chunk collection
- Delta calculation: chunk[len(previous):] to extract new content only
- Routes: /v1/chat/completions and /chat/completions (Open-WebUI compat)

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-30 10:31:14 +01:00
jpmschweitzer 0558a4556c chore: update Claude Code settings 2025-11-26 08:42:14 +01:00
jpmschweitzer 0c2c838766 feat(ai): complete Phase 2/3 documentation and memory system improvements
Phase completion and enhancement updates:

## Documentation Added
- Phase 2 completion: Memory system implementation details
- Phase 3 completion: Research capabilities and tool integration
- Session documentation: Model testing, VRAM optimization analysis
- Test results: Comprehensive prompt testing (v1_verbose: 87/100)
- Tool logging implementation guide

## System Prompts
- Added prompts.py with 7 tested variants for A/B testing
- v1_verbose, v2_concise, v3_imperative, v4_minimal, etc.
- Comprehensive testing results for each variant
- Production-ready prompt selection guidance

## Memory System Enhancements
- Multi-tenancy support: Added user_id parameter throughout
- System message filtering: Don't store system messages in history
- Improved conversation turn tracking with user isolation
- Enhanced memory manager for better multi-user support

## AI Controller Improvements
- Better memory integration with user_id support
- Enhanced error handling for memory operations
- Improved token tracking for usage monitoring
- Skip system message storage (part of agent state)

## Portainer Client
- Comprehensive API client (148 lines)
- Stack management and service monitoring
- Container operations with full error handling
- Async support for all operations

## Architecture Documentation
- Updated agent flow diagrams for ADK architecture
- Enhanced core-api README with current setup
- Updated Docker compose stack configuration
- Complete testing and validation documentation
2025-11-26 08:41:44 +01:00
jpmschweitzer e3b451b7b0 feat(ai): complete ADK migration and optimize system health checks
Major architectural changes and improvements:

## ADK Framework Migration (v0.10.0)
- Migrated from LangChain/LangGraph to Google ADK 1.3.0 with LiteLLM 1.80.5
- Improved tool calling reliability with local Ollama models
- Converted all 10 tools to ADK async generator format
- Updated streaming pipeline for ADK event system
- Enhanced error handling and agent initialization

## Model Optimization
- Switched from gemma3:12b (10GB VRAM) to gemma3:4b (4.8GB VRAM)
- Reduced VRAM usage from 91% to 43% (5.4GB freed)
- Optimized for production stability with memory headroom

## Health Check System Overhaul
- Optimized /health/full: 6ms response (was 30s+)
- Added model verification: confirms configured model is available
- New /health/diagnostics endpoint with optional deep testing
- Added currently loaded models tracking
- Clear emoji status indicators (//⚠️)
- Fixed AGENT_AVAILABLE flag export for proper health reporting

## Ollama Client Enhancements
- Added list_models() method for model inventory
- Enhanced model verification in health checks
- Better error handling and reporting

## Documentation Updates
- Updated STATUS.md to v0.10.0-adk-migration
- Comprehensive CHANGELOG.md entry with migration details
- Updated PLANS.md showing Phase 4 complete
- Updated ai-orchestrator-plan.md with ADK status
- Added MIGRATION_PLAN_LANGCHAIN_TO_ADK.md
- Added ADK_Ollama_Research.md with implementation analysis

## Technical Details
- 10 tools: 7 infrastructure + 2 research + 1 response tool
- Framework: Google ADK with UnifiedAgent pattern
- System prompt: v7_adk_best_practice
- Container health: Now passing Docker healthchecks
- Response times: Simple queries ~0.3-1s, Research ~4-7s
2025-11-26 08:36:50 +01:00
jpmschweitzer bfc58b03ba minor changes 2025-11-23 17:14:00 +01:00
jpmschweitzer db3260dd12 system prompt tweaks 2025-11-23 14:59:56 +01:00
jpmschweitzer 5e734ad27f ai-flow improvement / add langchain 2025-11-23 14:51:19 +01:00
jpmschweitzer ade84f34d5 add postgres-init to gitignore 2025-11-20 12:13:06 +01:00
jpmschweitzer cdbc2a5757 update organizr to use postgres-shared instead of sqlite 2025-11-20 12:10:18 +01:00
jpmschweitzer bf99ab5c8a update gitignore 2025-11-20 12:09:18 +01:00
jpmschweitzer e017c8a84c add gemini agent instructions 2025-11-20 12:08:57 +01:00
jpmschweitzer 0e3fef20fc restructure documentation 2025-11-20 10:17:09 +01:00
jpmschweitzer cb428a885d roll back authentik login. removed and restore working state. 2025-11-19 11:42:06 +01:00
jpmschweitzer e8eb2e954c security rework and memory optimilizations. 2025-11-17 08:48:00 +01:00
jpmschweitzer 72a653f494 add a tail script for the core-api 2025-11-14 17:30:45 +01:00
jpmschweitzer 3d7182bb7d remove obsolete code 2025-11-14 17:30:27 +01:00
jpmschweitzer d0d57cbe66 add tatlock logo for safekeeping 2025-11-14 17:12:19 +01:00
jpmschweitzer bdecaa8d65 moved documentation to look at the core-api openapi documentation. 2025-11-14 16:49:11 +01:00
jpmschweitzer 4eab463554 removed weirdness from main readme 2025-11-14 16:45:48 +01:00
jpmschweitzer 2c360e39a5 remove obsolete maintenance scripts (moved into fastapi) 2025-11-14 16:45:34 +01:00
jpmschweitzer 894f74fefb add core-api controllers to maintain portainer, npm and organizr deploys 2025-11-14 15:57:53 +01:00
jpmschweitzer 664fe55ff4 ok... ok... I'll add it to git... 2025-11-14 15:31:25 +01:00