This project is an autonomous agent framework that combines:
- Active Inference inspired action evaluation
- tool-based execution
- a parallel safety control plane
- persistent memory
- evidence-aware fallback behavior
The design goal is not only to complete tasks, but to do so with measurable safety and better runtime control than a naive reactive agent.
agent_manager.py- orchestrates the full control loop
- tracks cycles, failures, execution history, and working context
llm_interpreter.py- generates DAG plans and tool policies
look_ahead.py- predicts policy outcomes for non-safe actions
free_energy.py- computes Expected Free Energy
toolgate.py- executes validated tools
memory/memory_manager.py- semantic memory, episodic memory, and working context pruning
parallel_testing/*- safety control plane around execution
The runtime loop is:
- encode user goal
- generate DAG-style subtasks
- select next subtask
- choose next action
- estimate EFE
- pass action through execution gate
- execute the tool
- update beliefs and memory
- repeat until completion or halt
The action selection mechanism is based on:
G(pi) = Risk(pi) + Ambiguity(pi)
Where:
- Risk measures goal divergence and constraint violation
- Ambiguity measures uncertainty about predicted outcomes
The agent accepts low-EFE actions and refines or replans when EFE is too high.
The parallel testing suite is the most important runtime safety layer.
parallel_testing/events.py provides a singleton asynchronous event bus.
It emits and distributes events such as:
TASK_STARTEDPLAN_CREATEDGATE_VALIDATION_STARTEDOUTCOME_PREDICTEDSTEP_COMPLETEDGATE_REJECTEDTASK_COMPLETED
This lets safety modules observe execution without being tightly coupled to the main agent loop.
parallel_testing/execution_gate.py is the bottleneck for all tool actions.
Its behavior is:
- run policy checks
- if tool is low-risk, use fast-path validation
- otherwise run higher-cost safety checks in parallel
- allow or block the action
parallel_testing/policy_engine.py enforces hard policy rules before LLM reasoning is used.
Examples:
- constitution-level blocks
- deletion without approval
- path protections
parallel_testing/outcome_simulator.py predicts:
- likely result of an action
- side effects
- reversibility
- hidden adversarial interpretation
It includes Counter-Narrative Simulation, where the system asks how the same action could be maliciously reinterpreted.
parallel_testing/narrative_pressure_test.py adds a custom safety simulation.
It checks whether the same action becomes unsafe when wrapped in:
- urgency
- authority
- secrecy
- euphemism
- false benevolence
This creates a more original benchmark than ordinary refusal-only testing.
parallel_testing/parallel_judge.py combines:
- predicted outcome
- CNS warning
- narrative pressure score
into a final pre-execution allow/block decision for higher-risk actions.
parallel_testing/expectation_checker.py compares predicted and actual outcomes.
If divergence is high, it emits ANOMALY_DETECTED.
watchdog.pymonitors repeated anomalies and rejection patternsoversight_memory.pystores gate rejections for later auditing
Several optimizations were added to make the project usable interactively.
Low-risk tools no longer pay the full simulation and judge cost.
Examples:
search_memorystore_memoryread_fileweb_searchextract_inforeport_answer
For these tools, the execution gate only performs lightweight checks.
agent_manager.py now contains a heuristic router for repetitive low-risk subtasks.
This avoids calling the planner LLM for obvious patterns like:
- search memory
- web search
- summarize
- final answer
Repeated empty web searches no longer loop for long periods.
After repeated low-information failures, the agent marks the subtask as degraded and moves forward.
The post-run LLM judge is now configurable.
By default:
ENABLE_POST_RUN_JUDGE=FalseJUDGE_SAMPLES=1
This keeps the deep evaluator available without forcing every run to pay for it.
adapters/data_adapters.py now uses a cheap path for structured memory-style documents.
If evidence is irrelevant, it returns Not found instead of fabricating a vague summary.
One of the most important recent upgrades is evidence-grounded fallback.
Previously, the agent could:
- fail search
- still produce a generic answer
- look successful even when it had not verified anything
For research-like tasks, the final answer is now built with evidence checks:
- if relevant evidence exists, the summary is used
- if evidence is missing or irrelevant, the agent returns a transparent fallback
This behavior is implemented through:
_has_relevant_evidence()_build_final_answer()
inside agent_manager.py.
The memory layer includes:
- semantic memory through ChromaDB
- episodic action logging through SQLite
- working context compression using an LLM when the token budget is exceeded
This lets the agent retain:
- reusable factual context
- recent execution history
- condensed traces across long runs
The project now combines several safety layers:
- hard rule blocking
- action simulation
- adversarial reinterpretation
- rhetorical-pressure testing
- pragmatic pre-execution judging
- predicted-vs-actual anomaly detection
- audit logging
That layered design is stronger than relying on a single model refusal step.
- the expectation checker still uses lightweight lexical overlap instead of semantic similarity
- research answers are safer now, but retrieval quality still limits answer quality
- some tool selection remains heuristic and can still be improved
- the post-run judge is disabled by default for speed, so deep evaluation is not always present
- semantic relevance scoring for retrieved evidence
- source citation support in final research answers
- benchmark runner for mentor/demo scenarios
- explicit offline mode for retrieval failure
- richer anomaly classification
The strongest demonstrations for this repo are:
- Narrative Pressure Invariance
- Trojan Intent Reinterpretation
- Counterfactual Evidence Deprivation
Together they test:
- behavioral safety
- semantic safety
- epistemic honesty
EFE_THRESHOLD=0.65
MAX_REPLANS=3
LLM_TIMEOUT=90
ENABLE_POST_RUN_JUDGE=False
JUDGE_SAMPLES=1
DEBUG_MODE=TrueFocused safety/runtime tests:
python -m unittest test_parallel_testing.pyThis documentation reflects the current codebase state after:
- parallel testing suite integration
- narrative pressure test addition
- runtime fast-path optimization
- evidence-grounded fallback update