Spaces:
Sleeping
Sleeping
yc1838 commited on
Commit ·
9d361f6
1
Parent(s): 87e87cc
print more logs
Browse files- src/lilith_agent/app.py +9 -1
- tests/test_graph.py +20 -0
src/lilith_agent/app.py
CHANGED
|
@@ -819,5 +819,13 @@ def build_react_agent(cfg: Config):
|
|
| 819 |
lilith_home = Path(os.getenv("LILITH_HOME", ".lilith"))
|
| 820 |
memory_saver = build_checkpointer(lilith_home)
|
| 821 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 822 |
compiled = graph.compile(checkpointer=memory_saver)
|
| 823 |
-
return compiled.with_config({"recursion_limit":
|
|
|
|
| 819 |
lilith_home = Path(os.getenv("LILITH_HOME", ".lilith"))
|
| 820 |
memory_saver = build_checkpointer(lilith_home)
|
| 821 |
|
| 822 |
+
effective_recursion_limit = cfg.recursion_limit + cfg.budget_hard_cap + _FAIL_SAFE_RECURSION_HEADROOM
|
| 823 |
+
print(
|
| 824 |
+
f"[graph] effective_recursion_limit={effective_recursion_limit} "
|
| 825 |
+
f"logical_recursion_limit={cfg.recursion_limit} "
|
| 826 |
+
f"budget_hard_cap={cfg.budget_hard_cap} "
|
| 827 |
+
f"headroom={_FAIL_SAFE_RECURSION_HEADROOM}",
|
| 828 |
+
flush=True,
|
| 829 |
+
)
|
| 830 |
compiled = graph.compile(checkpointer=memory_saver)
|
| 831 |
+
return compiled.with_config({"recursion_limit": effective_recursion_limit})
|
tests/test_graph.py
CHANGED
|
@@ -71,6 +71,26 @@ def test_graph_returns_fail_safe_answer_when_hard_cap_hits_near_recursion_limit(
|
|
| 71 |
assert result["messages"][-1].content == "Final Answer: best effort answer"
|
| 72 |
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
def test_fail_safe_uses_unbound_model_to_prevent_more_tool_calls(monkeypatch, tmp_path):
|
| 75 |
class FakeBoundModel:
|
| 76 |
def __init__(self):
|
|
|
|
| 71 |
assert result["messages"][-1].content == "Final Answer: best effort answer"
|
| 72 |
|
| 73 |
|
| 74 |
+
def test_build_react_agent_prints_effective_recursion_limit(monkeypatch, tmp_path, capsys):
|
| 75 |
+
class FakeModel:
|
| 76 |
+
def bind_tools(self, tools):
|
| 77 |
+
return self
|
| 78 |
+
|
| 79 |
+
cfg = Config.from_env()
|
| 80 |
+
cfg.recursion_limit = 50
|
| 81 |
+
cfg.budget_hard_cap = 25
|
| 82 |
+
cfg.compact_summarize = False
|
| 83 |
+
monkeypatch.setenv("LILITH_HOME", str(tmp_path / ".lilith"))
|
| 84 |
+
monkeypatch.setattr("lilith_agent.app.get_extra_strong_model", lambda cfg: FakeModel())
|
| 85 |
+
monkeypatch.setattr("lilith_agent.app.get_cheap_model", lambda cfg: FakeModel())
|
| 86 |
+
monkeypatch.setattr("lilith_agent.tools.build_tools", lambda cfg: [echo_tool])
|
| 87 |
+
|
| 88 |
+
build_react_agent(cfg)
|
| 89 |
+
|
| 90 |
+
captured = capsys.readouterr().out
|
| 91 |
+
assert "[graph] effective_recursion_limit=79 logical_recursion_limit=50 budget_hard_cap=25 headroom=4" in captured
|
| 92 |
+
|
| 93 |
+
|
| 94 |
def test_fail_safe_uses_unbound_model_to_prevent_more_tool_calls(monkeypatch, tmp_path):
|
| 95 |
class FakeBoundModel:
|
| 96 |
def __init__(self):
|