mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-08 03:00:28 -04:00
This PR extracts backend changes from the hackathon/copilot branch, adding enhanced chat capabilities, agent management tools, store embeddings, and hybrid search functionality. ### Changes 🏗️ **Chat Features:** - Added chat database layer (`db.py`) for conversation and message persistence - Extended chat models with new types and response structures - New onboarding system prompt for guided user experiences - Enhanced chat routes with additional endpoints - Expanded chat service with more capabilities **Chat Agent Tools:** - `agent_output.py` - Handle agent execution outputs - `create_agent.py` - Tool for creating new agents via chat - `edit_agent.py` - Tool for modifying existing agents - `find_library_agent.py` - Search and discover library agents - Enhanced `run_agent.py` with additional functionality - New `models.py` for shared tool types **Store Enhancements:** - `embeddings.py` - Vector embeddings support for semantic search - `hybrid_search.py` - Combined keyword and semantic search - `backfill_embeddings.py` - Utility for backfilling existing data - Updated store database operations **Admin:** - Enhanced store admin routes **Data Layer:** - New `understanding.py` module for agent understanding/context **Database Migrations:** - `add_chat_tables` - Chat conversation and message tables - `add_store_embeddings` - Embeddings storage for store items - `enhance_search` - Search index improvements ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] Chat endpoints respond correctly - [x] Agent tools (create/edit/find/run) function properly - [x] Store embeddings and hybrid search work - [x] Database migrations apply cleanly #### For configuration changes: - [x] `.env.default` is updated or already compatible with my changes - [x] `docker-compose.yml` is updated or already compatible with my changes - [x] I have included a list of my configuration changes in the PR description (under **Changes**) --------- Co-authored-by: Torantulino <40276179@live.napier.ac.uk>
91 lines
3.1 KiB
Python
91 lines
3.1 KiB
Python
"""Configuration management for chat system."""
|
|
|
|
import os
|
|
|
|
from pydantic import Field, field_validator
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class ChatConfig(BaseSettings):
|
|
"""Configuration for the chat system."""
|
|
|
|
# OpenAI API Configuration
|
|
model: str = Field(
|
|
default="anthropic/claude-opus-4.5", description="Default model to use"
|
|
)
|
|
title_model: str = Field(
|
|
default="openai/gpt-4o-mini",
|
|
description="Model to use for generating session titles (should be fast/cheap)",
|
|
)
|
|
api_key: str | None = Field(default=None, description="OpenAI API key")
|
|
base_url: str | None = Field(
|
|
default="https://openrouter.ai/api/v1",
|
|
description="Base URL for API (e.g., for OpenRouter)",
|
|
)
|
|
|
|
# Session TTL Configuration - 12 hours
|
|
session_ttl: int = Field(default=43200, description="Session TTL in seconds")
|
|
|
|
# Streaming Configuration
|
|
max_context_messages: int = Field(
|
|
default=50, ge=1, le=200, description="Maximum context messages"
|
|
)
|
|
|
|
stream_timeout: int = Field(default=300, description="Stream timeout in seconds")
|
|
max_retries: int = Field(default=3, description="Maximum number of retries")
|
|
max_agent_runs: int = Field(default=3, description="Maximum number of agent runs")
|
|
max_agent_schedules: int = Field(
|
|
default=3, description="Maximum number of agent schedules"
|
|
)
|
|
|
|
# Langfuse Prompt Management Configuration
|
|
# Note: Langfuse credentials are in Settings().secrets (settings.py)
|
|
langfuse_prompt_name: str = Field(
|
|
default="CoPilot Prompt",
|
|
description="Name of the prompt in Langfuse to fetch",
|
|
)
|
|
|
|
@field_validator("api_key", mode="before")
|
|
@classmethod
|
|
def get_api_key(cls, v):
|
|
"""Get API key from environment if not provided."""
|
|
if v is None:
|
|
# Try to get from environment variables
|
|
# First check for CHAT_API_KEY (Pydantic prefix)
|
|
v = os.getenv("CHAT_API_KEY")
|
|
if not v:
|
|
# Fall back to OPEN_ROUTER_API_KEY
|
|
v = os.getenv("OPEN_ROUTER_API_KEY")
|
|
if not v:
|
|
# Fall back to OPENAI_API_KEY
|
|
v = os.getenv("OPENAI_API_KEY")
|
|
return v
|
|
|
|
@field_validator("base_url", mode="before")
|
|
@classmethod
|
|
def get_base_url(cls, v):
|
|
"""Get base URL from environment if not provided."""
|
|
if v is None:
|
|
# Check for OpenRouter or custom base URL
|
|
v = os.getenv("CHAT_BASE_URL")
|
|
if not v:
|
|
v = os.getenv("OPENROUTER_BASE_URL")
|
|
if not v:
|
|
v = os.getenv("OPENAI_BASE_URL")
|
|
if not v:
|
|
v = "https://openrouter.ai/api/v1"
|
|
return v
|
|
|
|
# Prompt paths for different contexts
|
|
PROMPT_PATHS: dict[str, str] = {
|
|
"default": "prompts/chat_system.md",
|
|
"onboarding": "prompts/onboarding_system.md",
|
|
}
|
|
|
|
class Config:
|
|
"""Pydantic config."""
|
|
|
|
env_file = ".env"
|
|
env_file_encoding = "utf-8"
|
|
extra = "ignore" # Ignore extra environment variables
|