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|
+
Three views: **system** (entry → graph → outputs), **ReAct graph** (state machine), **tool belt** (tool taxonomy + dependencies).
|
| 4 |
+
|
| 5 |
+
## System overview
|
| 6 |
+
|
| 7 |
+
```mermaid
|
| 8 |
+
flowchart TB
|
| 9 |
+
subgraph Entry["Entry points"]
|
| 10 |
+
TUI["tui.py<br/>(lilith CLI)"]
|
| 11 |
+
CLI["scripts/dev_run_gaia.py<br/>(batch runner)"]
|
| 12 |
+
APP["app.py<br/>(Gradio · HF Space)"]
|
| 13 |
+
end
|
| 14 |
+
|
| 15 |
+
subgraph Config["Config & models"]
|
| 16 |
+
CFG["config.py<br/>Config.from_env()"]
|
| 17 |
+
MDL["models.py<br/>cheap / strong / extra_strong<br/>+ NoThink / Retry wrappers"]
|
| 18 |
+
ENV[".env<br/>API keys · provider+model · caveman"]
|
| 19 |
+
ENV --> CFG --> MDL
|
| 20 |
+
end
|
| 21 |
+
|
| 22 |
+
subgraph Core["ReAct core"]
|
| 23 |
+
BUILD["app.py :: build_react_agent(cfg)"]
|
| 24 |
+
GRAPH["LangGraph<br/>StateGraph(AgentState)"]
|
| 25 |
+
RUN["runner.py<br/>run_agent_on_questions()"]
|
| 26 |
+
BUILD --> GRAPH
|
| 27 |
+
RUN --> GRAPH
|
| 28 |
+
end
|
| 29 |
+
|
| 30 |
+
subgraph Data["GAIA data sources"]
|
| 31 |
+
DS["gaia_dataset.py<br/>GaiaDatasetClient<br/>(HF dataset)"]
|
| 32 |
+
SCORE["ScoringApiClient<br/>(agents-course-unit4-<br/>scoring.hf.space)"]
|
| 33 |
+
end
|
| 34 |
+
|
| 35 |
+
subgraph Obs["Observability"]
|
| 36 |
+
LOG[".lilith/session-*.log"]
|
| 37 |
+
TRACE[".lilith/session-*.jsonl<br/>JsonlTraceCallback"]
|
| 38 |
+
ARIZE["Arize AX<br/>(optional)"]
|
| 39 |
+
LS["LangSmith<br/>(optional)"]
|
| 40 |
+
end
|
| 41 |
+
|
| 42 |
+
TUI --> BUILD
|
| 43 |
+
TUI --> Obs
|
| 44 |
+
CLI --> BUILD
|
| 45 |
+
CLI --> RUN
|
| 46 |
+
CLI --> DS
|
| 47 |
+
APP --> BUILD
|
| 48 |
+
APP --> RUN
|
| 49 |
+
APP --> SCORE
|
| 50 |
+
|
| 51 |
+
MDL --> BUILD
|
| 52 |
+
GRAPH --> Obs
|
| 53 |
+
|
| 54 |
+
CKPT[".checkpoints/<task_id>.json"]
|
| 55 |
+
RUN --> CKPT
|
| 56 |
+
```
|
| 57 |
+
|
| 58 |
+
## ReAct graph (state machine)
|
| 59 |
+
|
| 60 |
+
```mermaid
|
| 61 |
+
stateDiagram-v2
|
| 62 |
+
[*] --> model
|
| 63 |
+
model --> tools: AIMessage has tool_calls<br/>AND iterations < limit<br/>AND calls < BUDGET_HARD_CAP (25)
|
| 64 |
+
model --> fail_safe: iterations ≥ recursion_limit − 2<br/>OR calls ≥ BUDGET_HARD_CAP
|
| 65 |
+
model --> [*]: no tool_calls (final answer)
|
| 66 |
+
tools --> model: results appended as ToolMessages
|
| 67 |
+
fail_safe --> [*]: emergency summary
|
| 68 |
+
note right of model
|
| 69 |
+
compact old ToolMessages
|
| 70 |
+
(keep last 4 verbatim,
|
| 71 |
+
truncate older to 300 chars)
|
| 72 |
+
inject BUDGET WARNING at 15 calls
|
| 73 |
+
apply caveman prompt wrapper
|
| 74 |
+
end note
|
| 75 |
+
note left of tools
|
| 76 |
+
per-call guards:
|
| 77 |
+
1. exact (name,args) dedup
|
| 78 |
+
2. semantic dedup (Jaccard ≥ 0.5) for tavily
|
| 79 |
+
3. per-tool error cooldown (3 fails → freeze)
|
| 80 |
+
end note
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
## Tool belt
|
| 84 |
+
|
| 85 |
+
```mermaid
|
| 86 |
+
flowchart LR
|
| 87 |
+
subgraph Web["Web & search"]
|
| 88 |
+
WS["web_search<br/>(DDG → Tavily fallback)"]
|
| 89 |
+
FU["fetch_url<br/>(trafilatura)"]
|
| 90 |
+
end
|
| 91 |
+
|
| 92 |
+
subgraph Code["Code & files"]
|
| 93 |
+
RP["run_python<br/>(sandboxed subprocess)"]
|
| 94 |
+
RF["read_file"]
|
| 95 |
+
LS_T["ls · grep · glob_files · write_file"]
|
| 96 |
+
end
|
| 97 |
+
|
| 98 |
+
subgraph Media["Media"]
|
| 99 |
+
AUD["transcribe_audio<br/>(faster-whisper)"]
|
| 100 |
+
PDF["inspect_pdf"]
|
| 101 |
+
VIS["inspect_visual_content<br/>(Gemini → FAL → cross-provider)"]
|
| 102 |
+
YT_T["youtube_transcript"]
|
| 103 |
+
YT_F["youtube_frame_at<br/>(ffmpeg)"]
|
| 104 |
+
end
|
| 105 |
+
|
| 106 |
+
subgraph Academic["Academic"]
|
| 107 |
+
AX["arxiv_search"]
|
| 108 |
+
CR["crossref_search"]
|
| 109 |
+
CJ["count_journal_articles"]
|
| 110 |
+
FE["filter_entities"]
|
| 111 |
+
end
|
| 112 |
+
|
| 113 |
+
subgraph Plan["Planning"]
|
| 114 |
+
WT["write_todos"]
|
| 115 |
+
MD["mark_todo_done"]
|
| 116 |
+
end
|
| 117 |
+
|
| 118 |
+
REG["tools/__init__.py<br/>build_tools(cfg)"]
|
| 119 |
+
REG --> Web
|
| 120 |
+
REG --> Code
|
| 121 |
+
REG --> Media
|
| 122 |
+
REG --> Academic
|
| 123 |
+
REG --> Plan
|
| 124 |
+
|
| 125 |
+
VIS -. fallback chain .-> VIS
|
| 126 |
+
YT_F --> VIS
|
| 127 |
+
CR --> FE
|
| 128 |
+
```
|
| 129 |
+
|
| 130 |
+
## Key sources
|
| 131 |
+
|
| 132 |
+
| Concern | File |
|
| 133 |
+
|---|---|
|
| 134 |
+
| ReAct graph + routing + dedup | [src/lilith_agent/app.py](src/lilith_agent/app.py) |
|
| 135 |
+
| Batch runner + checkpoints | [src/lilith_agent/runner.py](src/lilith_agent/runner.py) |
|
| 136 |
+
| Config loader | [src/lilith_agent/config.py](src/lilith_agent/config.py) |
|
| 137 |
+
| Model provider factory | [src/lilith_agent/models.py](src/lilith_agent/models.py) |
|
| 138 |
+
| Tool registry | [src/lilith_agent/tools/__init__.py](src/lilith_agent/tools/__init__.py) |
|
| 139 |
+
| Logging + Arize + JSONL trace | [src/lilith_agent/observability.py](src/lilith_agent/observability.py) |
|
| 140 |
+
| HF dataset client | [src/lilith_agent/gaia_dataset.py](src/lilith_agent/gaia_dataset.py) |
|
| 141 |
+
| Gradio Space entry | [app.py](app.py) |
|
| 142 |
+
| Interactive TUI | [src/lilith_agent/tui.py](src/lilith_agent/tui.py) |
|
| 143 |
+
| GAIA batch CLI | [scripts/dev_run_gaia.py](scripts/dev_run_gaia.py) |
|