Download apps/api/tests/test_agent_memory_off.py from aliroya/contiai: direct link, hf CLI and curl.
- Browser
- Download file 3.9 kB
-
https://huggingface.co/spaces/aliroya/contiai/resolve/main/apps/api/tests/test_agent_memory_off.py
- Command line
-
hf download hf://spaces/aliroya/contiai/apps/api/tests/test_agent_memory_off.py
-
curl -L -o test_agent_memory_off.py https://huggingface.co/spaces/aliroya/contiai/resolve/main/apps/api/tests/test_agent_memory_off.py
3.9 kB
| """CrewAI memory is off for the book agents, because it never worked. | |
| Across every recorded run: | |
| memory_save_started 42 | |
| memory_save_completed 0 | |
| memory_save_failed 53 | |
| and the store directory - `AppData/Local/CrewAI/api/memory` - is empty. No | |
| embedder is configured, so every save fails and every search reads nothing. | |
| It was not free while doing nothing. Memory attaches `search_memory` and | |
| `save_to_memory` to the agent, and each tool round-trip resends the entire | |
| prompt: 20,564 characters for the writer, three times per subsection. The book | |
| made 298 calls for 75 subsections where 150 would do, about $1.30. | |
| Had it worked it would have been a hazard. The store is machine-wide, so one | |
| client's book could recall passages from another's. What memory was meant to | |
| prevent - a subsection repeating its neighbours - is already prevented by | |
| `avoid_overlap_with`, which the planner writes per subsection and which names | |
| the titles rather than hoping a similarity search finds them. | |
| """ | |
| from __future__ import annotations | |
| import inspect | |
| import pytest | |
| BOOK_AGENTS = [ | |
| ("app.agents.books.book_content", "make_writer_agent"), | |
| ("app.agents.books.book_content", "make_quality_agent"), | |
| ] | |
| def test_the_book_agents_do_not_enable_memory(module_name, factory): | |
| import importlib | |
| module = importlib.import_module(module_name) | |
| source = inspect.getsource(getattr(module, factory)) | |
| assert "memory=True" not in source, f"{factory} still enables memory" | |
| def test_the_planner_does_not_enable_memory(): | |
| from app.agents.books.book_planning import agent_task_planning | |
| source = inspect.getsource(agent_task_planning) | |
| assert "memory=True" not in source | |
| assert "memory=False" in source | |
| def test_nothing_on_the_book_path_enables_memory(): | |
| """A third agent appearing on the path later would carry the same cost | |
| silently, so the whole path is scanned rather than the two known files. | |
| Both layers are read: the steps import some agents directly, and the | |
| planner is reached through `planning_services` instead - checking only the | |
| step module missed it entirely on the first version of this test. | |
| """ | |
| import pathlib | |
| api = pathlib.Path(inspect.getfile( | |
| __import__("app.pipelines.books.steps", fromlist=["x"]))).parents[3] | |
| callers = "\n".join( | |
| path.read_text(encoding="utf-8") | |
| for folder in ("pipelines/books", "services/books") | |
| for path in (api / "app" / folder).glob("*.py") | |
| ) | |
| agents = api / "app" / "agents" / "books" | |
| offenders = [ | |
| path.name | |
| for path in sorted(agents.glob("*.py")) | |
| if path.stem in callers and "memory=True" in path.read_text(encoding="utf-8") | |
| ] | |
| assert not offenders, f"memory is still on in: {offenders}" | |
| def test_the_reason_is_recorded_against_the_fidelity_guard(): | |
| """Both files are carried over from the original tree, so the switch has to | |
| be written down as a permitted change rather than pass unnoticed.""" | |
| from tests.test_ported_fidelity import INTENTIONAL | |
| for key in ("agents/books/book_content.py", "agents/books/book_planning.py"): | |
| assert key in INTENTIONAL, f"{key} changed without a recorded reason" | |
| reason, allowed = INTENTIONAL[key] | |
| assert "memory" in reason | |
| assert " memory=True," in allowed | |
| def test_overlap_is_still_prevented_by_the_plan(): | |
| """The thing memory was supposed to do. It is done by a field the planner | |
| fills per subsection, and it survives this change untouched.""" | |
| from app.services.books.content_services import build_inputs | |
| inputs = build_inputs( | |
| {}, {"chapter_intro": {}}, {}, "موضوع", | |
| {"avoid_overlap_with": ["موضوع سابق", "موضوع آخر"]}, | |
| ) | |
| assert "موضوع سابق" in inputs["avoid_overlap_with"] | |