Merge pull request 'Agent scaffolding: config, state schema, tracing' (#18) from feature/agent-scaffolding into main
This commit is contained in:
commit
7d30ce7100
4 changed files with 83 additions and 0 deletions
0
app/__init__.py
Normal file
0
app/__init__.py
Normal file
26
app/config.py
Normal file
26
app/config.py
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
"""Central, environment-driven configuration for the agent."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
|
load_dotenv()
|
||||||
|
|
||||||
|
PROJECT_ROOT = Path(__file__).resolve().parent.parent
|
||||||
|
|
||||||
|
OLLAMA_MODEL = os.getenv("OLLAMA_MODEL", "llama3.2:3b")
|
||||||
|
OLLAMA_BASE_URL = os.getenv("OLLAMA_BASE_URL", "http://localhost:11434")
|
||||||
|
|
||||||
|
EMBEDDING_MODEL = os.getenv("EMBEDDING_MODEL", "sentence-transformers/all-MiniLM-L6-v2")
|
||||||
|
|
||||||
|
POLICY_DOCS_DIR = Path(os.getenv("POLICY_DOCS_DIR", PROJECT_ROOT / "app" / "data" / "policies"))
|
||||||
|
INDEX_DIR = Path(os.getenv("INDEX_DIR", PROJECT_ROOT / "app" / "data" / "index"))
|
||||||
|
TICKETS_DB_PATH = Path(os.getenv("TICKETS_DB_PATH", PROJECT_ROOT / "app" / "data" / "tickets.db"))
|
||||||
|
|
||||||
|
RAG_TOP_K = int(os.getenv("RAG_TOP_K", "4"))
|
||||||
|
RAG_MAX_REWRITES = int(os.getenv("RAG_MAX_REWRITES", "2"))
|
||||||
|
|
||||||
|
CHUNK_SIZE = int(os.getenv("CHUNK_SIZE", "500"))
|
||||||
|
CHUNK_OVERLAP = int(os.getenv("CHUNK_OVERLAP", "50"))
|
||||||
48
app/state.py
Normal file
48
app/state.py
Normal file
|
|
@ -0,0 +1,48 @@
|
||||||
|
"""Shared state schemas for the main agent graph and the RAG subgraph."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import Any, Optional, TypedDict
|
||||||
|
|
||||||
|
|
||||||
|
class TraceStep(TypedDict):
|
||||||
|
node: str
|
||||||
|
detail: str
|
||||||
|
duration_ms: float
|
||||||
|
|
||||||
|
|
||||||
|
class AgentState(TypedDict, total=False):
|
||||||
|
# Input
|
||||||
|
user_query: str
|
||||||
|
|
||||||
|
# Planning / decomposition (filled by classify_intent)
|
||||||
|
pending_tasks: list[str] # ordered queue of task types still to execute
|
||||||
|
rag_query: str # query to send into the RAG subgraph
|
||||||
|
calc_args: dict[str, Any] # extracted args for leave_balance_calculator
|
||||||
|
ticket_args: dict[str, Any] # extracted args for create_support_ticket
|
||||||
|
is_out_of_scope: bool
|
||||||
|
|
||||||
|
# Intermediate results, keyed by task type
|
||||||
|
results: dict[str, Any]
|
||||||
|
|
||||||
|
# Autonomous escalation flag, set by rag_answer on low-confidence RAG result
|
||||||
|
escalate: bool
|
||||||
|
escalate_reason: str
|
||||||
|
|
||||||
|
# Observability
|
||||||
|
trace: list[TraceStep]
|
||||||
|
|
||||||
|
# Output
|
||||||
|
final_answer: str
|
||||||
|
|
||||||
|
|
||||||
|
class RagState(TypedDict, total=False):
|
||||||
|
query: str
|
||||||
|
original_query: str
|
||||||
|
retries: int
|
||||||
|
max_retries: int
|
||||||
|
docs: list[dict[str, Any]] # [{"content": ..., "source": ..., "score": ...}]
|
||||||
|
relevant: bool
|
||||||
|
answer: str
|
||||||
|
confidence: str # "high" | "low"
|
||||||
|
sources: list[str]
|
||||||
|
trace: list[TraceStep]
|
||||||
9
app/tracing.py
Normal file
9
app/tracing.py
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
"""Tiny shared helper for building trace entries used by both graphs and the Streamlit UI."""
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
|
|
||||||
|
def trace_step(state: dict, node: str, detail: str, start: float) -> dict:
|
||||||
|
step = {"node": node, "detail": detail, "duration_ms": round((time.time() - start) * 1000, 1)}
|
||||||
|
return {"trace": state.get("trace", []) + [step]}
|
||||||
Loading…
Add table
Reference in a new issue