Spaces:
Sleeping
Sleeping
yc1838 commited on
Commit ·
f797178
1
Parent(s): abd5331
lint
Browse files- src/lilith_agent/app.py +5 -4
- src/lilith_agent/memory.py +0 -7
- src/lilith_agent/tui.py +5 -5
- tests/test_memory_pick_up.py +3 -2
- tests/test_observability.py +3 -3
- tests/test_vision.py +4 -3
src/lilith_agent/app.py
CHANGED
|
@@ -15,6 +15,11 @@ from langgraph.graph import END, StateGraph
|
|
| 15 |
from langgraph.graph.message import add_messages
|
| 16 |
from typing import Annotated, TypedDict
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
class AgentState(TypedDict):
|
| 19 |
messages: Annotated[list, add_messages]
|
| 20 |
iterations: int
|
|
@@ -26,10 +31,6 @@ class AgentState(TypedDict):
|
|
| 26 |
supervisor_review_count: int
|
| 27 |
|
| 28 |
|
| 29 |
-
from lilith_agent.config import Config
|
| 30 |
-
from lilith_agent.checkpointing import build_checkpointer
|
| 31 |
-
from lilith_agent.models import get_cheap_model, get_extra_strong_model
|
| 32 |
-
|
| 33 |
log = logging.getLogger(__name__)
|
| 34 |
# Per-node child loggers so the logger-name column reads `lilith_agent.nodes.X`
|
| 35 |
# and traces read like the gaia_agent reference output (`[model] invoking ...`,
|
|
|
|
| 15 |
from langgraph.graph.message import add_messages
|
| 16 |
from typing import Annotated, TypedDict
|
| 17 |
|
| 18 |
+
from lilith_agent.config import Config
|
| 19 |
+
from lilith_agent.checkpointing import build_checkpointer
|
| 20 |
+
from lilith_agent.models import get_cheap_model, get_extra_strong_model
|
| 21 |
+
|
| 22 |
+
|
| 23 |
class AgentState(TypedDict):
|
| 24 |
messages: Annotated[list, add_messages]
|
| 25 |
iterations: int
|
|
|
|
| 31 |
supervisor_review_count: int
|
| 32 |
|
| 33 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
log = logging.getLogger(__name__)
|
| 35 |
# Per-node child loggers so the logger-name column reads `lilith_agent.nodes.X`
|
| 36 |
# and traces read like the gaia_agent reference output (`[model] invoking ...`,
|
src/lilith_agent/memory.py
CHANGED
|
@@ -305,13 +305,6 @@ def summarize_episode(messages: List[BaseMessage], model) -> None:
|
|
| 305 |
if "ERROR" in content.upper():
|
| 306 |
outcome = "failed/struggled"
|
| 307 |
|
| 308 |
-
conv_parts = []
|
| 309 |
-
for m in messages:
|
| 310 |
-
content = _content_to_text(m.content)
|
| 311 |
-
if content:
|
| 312 |
-
conv_parts.append(f"{m.type}: {content[:200]}...")
|
| 313 |
-
conv_str = "\n".join(conv_parts)
|
| 314 |
-
|
| 315 |
prompt = f"""
|
| 316 |
Summarize this task trajectory for Lilith's 'Episodic Memory'.
|
| 317 |
Initial Question: {initial_question}
|
|
|
|
| 305 |
if "ERROR" in content.upper():
|
| 306 |
outcome = "failed/struggled"
|
| 307 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 308 |
prompt = f"""
|
| 309 |
Summarize this task trajectory for Lilith's 'Episodic Memory'.
|
| 310 |
Initial Question: {initial_question}
|
src/lilith_agent/tui.py
CHANGED
|
@@ -1,14 +1,11 @@
|
|
| 1 |
import sys
|
| 2 |
import uuid
|
| 3 |
from pathlib import Path
|
| 4 |
-
from dotenv import load_dotenv
|
| 5 |
-
|
| 6 |
-
env_path = Path(__file__).resolve().parent.parent.parent / ".env"
|
| 7 |
-
load_dotenv(dotenv_path=env_path, override=True)
|
| 8 |
|
|
|
|
| 9 |
from rich.console import Console
|
| 10 |
-
from rich.panel import Panel
|
| 11 |
from rich.markdown import Markdown
|
|
|
|
| 12 |
from rich.live import Live
|
| 13 |
from rich.spinner import Spinner
|
| 14 |
from rich.theme import Theme
|
|
@@ -19,6 +16,9 @@ from lilith_agent.config import Config
|
|
| 19 |
from lilith_agent.app import build_react_agent
|
| 20 |
from lilith_agent.observability import setup_logging, setup_arize, JsonlTraceCallback
|
| 21 |
|
|
|
|
|
|
|
|
|
|
| 22 |
custom_theme = Theme({
|
| 23 |
"info": "dim cyan",
|
| 24 |
"warning": "magenta",
|
|
|
|
| 1 |
import sys
|
| 2 |
import uuid
|
| 3 |
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
from rich.console import Console
|
|
|
|
| 7 |
from rich.markdown import Markdown
|
| 8 |
+
from rich.panel import Panel
|
| 9 |
from rich.live import Live
|
| 10 |
from rich.spinner import Spinner
|
| 11 |
from rich.theme import Theme
|
|
|
|
| 16 |
from lilith_agent.app import build_react_agent
|
| 17 |
from lilith_agent.observability import setup_logging, setup_arize, JsonlTraceCallback
|
| 18 |
|
| 19 |
+
env_path = Path(__file__).resolve().parent.parent.parent / ".env"
|
| 20 |
+
load_dotenv(dotenv_path=env_path, override=True)
|
| 21 |
+
|
| 22 |
custom_theme = Theme({
|
| 23 |
"info": "dim cyan",
|
| 24 |
"warning": "magenta",
|
tests/test_memory_pick_up.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from lilith_agent.memory import _store, retrieve_relevant_context
|
| 2 |
|
| 3 |
# Initialize DB via _store
|
| 4 |
_store._init_db()
|
| 5 |
|
| 6 |
# Manually inject
|
| 7 |
-
from datetime import datetime
|
| 8 |
-
import sqlite3
|
| 9 |
conn = sqlite3.connect(str(_store.db_path))
|
| 10 |
with conn:
|
| 11 |
conn.execute("DELETE FROM memories")
|
|
|
|
| 1 |
+
import sqlite3
|
| 2 |
+
from datetime import datetime
|
| 3 |
+
|
| 4 |
from lilith_agent.memory import _store, retrieve_relevant_context
|
| 5 |
|
| 6 |
# Initialize DB via _store
|
| 7 |
_store._init_db()
|
| 8 |
|
| 9 |
# Manually inject
|
|
|
|
|
|
|
| 10 |
conn = sqlite3.connect(str(_store.db_path))
|
| 11 |
with conn:
|
| 12 |
conn.execute("DELETE FROM memories")
|
tests/test_observability.py
CHANGED
|
@@ -62,7 +62,7 @@ def test_jsonl_callback_captures_chat_model_payload(tmp_path):
|
|
| 62 |
messages = [[SystemMessage(content="sys"), HumanMessage(content="hi")]]
|
| 63 |
cb.on_chat_model_start({"name": "ChatAnthropic"}, messages, run_id="r0")
|
| 64 |
|
| 65 |
-
events = [json.loads(
|
| 66 |
assert events[0]["event"] == "chat_model_start"
|
| 67 |
assert events[0]["model"] == "ChatAnthropic"
|
| 68 |
assert any(m["type"] == "system" and m["content"] == "sys" for m in events[0]["messages"][0])
|
|
@@ -76,7 +76,7 @@ def test_jsonl_callback_captures_chain_boundaries(tmp_path):
|
|
| 76 |
cb.on_chain_start({"name": "agent"}, {"messages": []}, run_id="c1")
|
| 77 |
cb.on_chain_end({"messages": ["ok"]}, run_id="c1")
|
| 78 |
|
| 79 |
-
events = [json.loads(
|
| 80 |
assert events[0]["event"] == "chain_start"
|
| 81 |
assert events[0]["name"] == "agent"
|
| 82 |
assert events[1]["event"] == "chain_end"
|
|
@@ -130,7 +130,7 @@ def test_jsonl_callback_writes_tool_and_llm_events(tmp_path):
|
|
| 130 |
|
| 131 |
lines = path.read_text().strip().splitlines()
|
| 132 |
assert len(lines) == 3
|
| 133 |
-
events = [json.loads(
|
| 134 |
assert events[0]["event"] == "tool_start"
|
| 135 |
assert events[0]["name"] == "web_search"
|
| 136 |
assert events[0]["input"] == "moon perigee"
|
|
|
|
| 62 |
messages = [[SystemMessage(content="sys"), HumanMessage(content="hi")]]
|
| 63 |
cb.on_chat_model_start({"name": "ChatAnthropic"}, messages, run_id="r0")
|
| 64 |
|
| 65 |
+
events = [json.loads(line) for line in (tmp_path / "trace.jsonl").read_text().splitlines()]
|
| 66 |
assert events[0]["event"] == "chat_model_start"
|
| 67 |
assert events[0]["model"] == "ChatAnthropic"
|
| 68 |
assert any(m["type"] == "system" and m["content"] == "sys" for m in events[0]["messages"][0])
|
|
|
|
| 76 |
cb.on_chain_start({"name": "agent"}, {"messages": []}, run_id="c1")
|
| 77 |
cb.on_chain_end({"messages": ["ok"]}, run_id="c1")
|
| 78 |
|
| 79 |
+
events = [json.loads(line) for line in (tmp_path / "trace.jsonl").read_text().splitlines()]
|
| 80 |
assert events[0]["event"] == "chain_start"
|
| 81 |
assert events[0]["name"] == "agent"
|
| 82 |
assert events[1]["event"] == "chain_end"
|
|
|
|
| 130 |
|
| 131 |
lines = path.read_text().strip().splitlines()
|
| 132 |
assert len(lines) == 3
|
| 133 |
+
events = [json.loads(line) for line in lines]
|
| 134 |
assert events[0]["event"] == "tool_start"
|
| 135 |
assert events[0]["name"] == "web_search"
|
| 136 |
assert events[0]["input"] == "moon perigee"
|
tests/test_vision.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
import os
|
| 2 |
-
from dotenv import load_dotenv
|
| 3 |
|
| 4 |
-
|
| 5 |
-
load_dotenv(override=True)
|
| 6 |
|
| 7 |
from lilith_agent.config import Config
|
| 8 |
from lilith_agent.tools.vision import inspect_visual_content
|
| 9 |
|
|
|
|
|
|
|
|
|
|
| 10 |
def test_fal_vision_integration(tmp_path):
|
| 11 |
"""
|
| 12 |
Test the FAL vision integration using GAIA task 8f80e01c-1296-4371-9486-bb3d68651a60.
|
|
|
|
| 1 |
import os
|
|
|
|
| 2 |
|
| 3 |
+
from dotenv import load_dotenv
|
|
|
|
| 4 |
|
| 5 |
from lilith_agent.config import Config
|
| 6 |
from lilith_agent.tools.vision import inspect_visual_content
|
| 7 |
|
| 8 |
+
# Load .env before evaluating test configuration.
|
| 9 |
+
load_dotenv(override=True)
|
| 10 |
+
|
| 11 |
def test_fal_vision_integration(tmp_path):
|
| 12 |
"""
|
| 13 |
Test the FAL vision integration using GAIA task 8f80e01c-1296-4371-9486-bb3d68651a60.
|