A command-line research agent tackling engineering problems for reliable agentic systems:
- bounded agent loops;
- typed tool contracts;
- hybrid retrieval;
- explicit memory policy;
- concurrent specialist workers;
- durable checkpoint recovery;
- controlled external research;
- provenance-preserving evidence;
- deterministic and model-based agent evaluations.
The project intentionally emphasizes runtime correctness, observability, failure containment, and evaluation over frontend development.
The model proposes actions, but the application runtime retains execution authority.
model proposal
↓
typed decision parser
↓
tool registry and schema validation
↓
policy and budget checks
↓
tool execution
↓
structured observation
↓
next bounded decision
The loop enforces:
- validated tool names and arguments;
- maximum step limits;
- structured decisions;
- deterministic termination;
- trace events;
- provider-neutral model interfaces.
The local retrieval system supports:
- deterministic Markdown and text ingestion;
- stable document and chunk identifiers;
- overlapping word-window chunking;
- dense vector retrieval;
- BM25 lexical retrieval;
- reciprocal-rank fusion;
- Recall@k evaluation.
documents
↓
typed ingestion
↓
stable chunking
├── dense retrieval
└── BM25 retrieval
↓
reciprocal-rank fusion
↓
ranked source-preserving evidence
Long-term memory is not the same thing as conversation history.
The memory subsystem provides:
- explicit allowlisted memory categories;
- user and session ownership;
- policy validation before persistence;
- semantic recall;
- deletion by logical memory identifier;
- a Supermemory provider adapter;
- deterministic in-memory tests.
Supported memory categories include:
user_preferencedurable_factresearch_interestsession_summary
A deterministic planner creates three independent specialist assignments:
| Worker | Responsibility |
|---|---|
papers |
Research findings, benchmarks, empirical evidence, and limitations |
documentation_code |
APIs, architecture, implementation guidance, and engineering constraints |
skeptic |
Counterexamples, unsupported assumptions, risks, and missing evidence |
The supervisor enforces:
- maximum worker count;
- maximum concurrency;
- per-worker decision budgets;
- per-worker tool budgets;
- stable result ordering;
- failure isolation;
- cancellation propagation;
- observable peak concurrency.
The durable runtime uses LangGraph with SQLite checkpoints.
It supports:
- stable run identifiers;
- plan fingerprints;
- checkpointed worker state;
- application-owned timeouts;
- bounded retry attempts;
- attempt records;
- resume after interruption;
- prevention of repeated successful work;
- refusal to reuse a run ID with a different plan.
The live-web-search command connects the orchestration runtime to:
- arXiv;
- Crossref;
- Semantic Scholar;
- official documentation pages;
- exact GitHub repository files at explicit refs;
- administrator-approved web pages.
This is not unrestricted web browsing.
Scholarly providers perform query-based search. Documentation, GitHub, and controlled-web sources operate only on targets defined in the local allowlist.
External evidence is normalized with:
- provider identity;
- canonical URL;
- publication metadata;
- DOI, arXiv, and Semantic Scholar identifiers;
- canonical cross-provider identity;
- provider lineage;
- content hashes;
- evidence scope;
- prompt-injection risk flags;
- synthesis eligibility.
The evaluation subsystem runs complete tasks rather than testing isolated prompts.
It supports:
- task suites;
- repeated trials;
- multiple graders;
- deterministic and Gemini profiles;
- observable trajectories;
- citation-integrity checks;
- tool and model call counts;
- latency percentiles;
- nominal token-cost estimates;
- baseline comparisons;
- regression gates;
- JSON, Markdown, and JSONL artifacts.
flowchart TD
CLI[Typer CLI] --> Planner[Deterministic Planner]
Planner --> Supervisor[Bounded Research Supervisor]
Supervisor --> Papers[Paper Worker]
Supervisor --> Docs[Documentation and Code Worker]
Supervisor --> Skeptic[Skeptic Worker]
Papers --> PaperRouter[Paper Source Route]
Docs --> EngineeringRouter[Engineering Source Route]
Skeptic --> CombinedRouter[Combined Skeptical Route]
PaperRouter --> Arxiv[arXiv]
PaperRouter --> Crossref[Crossref]
PaperRouter --> S2[Semantic Scholar]
EngineeringRouter --> OfficialDocs[Official Documentation]
EngineeringRouter --> GitHub[Exact GitHub Files]
EngineeringRouter --> Web[Controlled Web Pages]
CombinedRouter --> Federation[Federated Search]
Arxiv --> Federation
Crossref --> Federation
S2 --> Federation
OfficialDocs --> Federation
GitHub --> Federation
Web --> Federation
Federation --> Identity[Identity Resolution and Deduplication]
Identity --> Security[Evidence Security Gate]
Security --> Evidence[Typed Evidence]
Evidence --> Results[Worker Results and Trace]
Results --> Evals[Evaluation Harness]
Supervisor --> Durable[LangGraph and SQLite Checkpoints]
CLI --> Memory[Policy-Controlled Memory]
src/research_agent/
├── cli.py
├── domain.py
├── loop.py
├── ports.py
├── tools.py
├── durable/
│ ├── graph.py
│ ├── models.py
│ ├── policy.py
│ ├── runtime.py
│ └── synthesis.py
├── evaluation/
│ ├── gemini.py
│ ├── graders.py
│ ├── harness.py
│ ├── metrics.py
│ ├── models.py
│ ├── pricing.py
│ ├── regression.py
│ ├── reporting.py
│ └── systems.py
├── memory/
│ ├── in_memory.py
│ ├── models.py
│ ├── policy.py
│ ├── service.py
│ └── supermemory.py
├── orchestration/
│ ├── models.py
│ ├── planner.py
│ ├── ports.py
│ ├── supervisor.py
│ └── worker.py
├── retrieval/
│ ├── bm25.py
│ ├── chunking.py
│ ├── dense.py
│ ├── embeddings.py
│ ├── evaluation.py
│ ├── hybrid.py
│ ├── ingestion.py
│ ├── lab.py
│ ├── models.py
│ └── ports.py
└── sources/
├── adapters.py
├── evidence.py
├── federation.py
├── http.py
├── identity.py
├── ledger.py
├── live.py
├── routing.py
├── scholarly.py
├── security.py
└── web.py
- Python 3.12 or newer
- uv
- Internet access only for live-source, Supermemory, or Gemini operations
- A Crossref contact email for live scholarly research
A GPU is optional. Local embeddings can run on CPU.
Clone the repository and enter it:
git clone YOUR_REPOSITORY_URL
cd research-cli-agentInstall the project and development dependencies:
uv syncInspect the CLI:
uv run research-agent --helpThe first local dense-retrieval run may download the configured Sentence Transformers model.
Set only the credentials required for the features you use.
# Required for live external research
$env:CROSSREF_MAILTO="your-email@example.com"
# Optional live-source credentials
$env:SEMANTIC_SCHOLAR_API_KEY="your-semantic-scholar-key"
$env:GITHUB_TOKEN="your-github-token"
# Required for Supermemory commands
$env:SUPERMEMORY_API_KEY="your-supermemory-key"
# Required for Gemini evaluation
$env:GEMINI_API_KEY="your-gemini-key"Never commit real credentials.
The project includes .env.example as documentation, but does not automatically load .env files.
uv run research-agent demo `
"reliable agents preserve explicit state"Show or hide the execution trace:
uv run research-agent demo `
--no-trace `
"reliable agents preserve explicit state"uv run research-agent retrieve `
--corpus examples/corpus `
--mode hybrid `
--top-k 5 `
--device cpu `
"agent checkpoint recovery"Available retrieval modes:
densebm25hybrid
uv run research-agent research `
--corpus examples/corpus `
--device cpu `
"How should production agents recover from tool failures?"uv run research-agent durable-research `
--run-id recovery-study-001 `
--checkpoint-db .state/research.sqlite `
--worker-timeout 15 `
--max-attempts 2 `
--corpus examples/corpus `
--device cpu `
"How should production agents recover from partial failure?"Run the same command again with the same run ID and plan to resume or reuse completed state.
A reused run ID with a different plan is rejected.
configs/live_sources.json defines the exact documentation, GitHub, and controlled-web targets that the runtime may access.
Example:
{
"official_documentation": [
{
"title": "Python asyncio tasks and task groups",
"url": "https://docs.python.org/3/library/asyncio-task.html"
}
],
"github": [
{
"owner": "python",
"repository": "cpython",
"path": "Lib/asyncio/taskgroups.py",
"ref": "v3.13.5"
}
],
"controlled_web": [
{
"title": "Anthropic — Building Effective AI Agents",
"url": "https://www.anthropic.com/engineering/building-effective-agents"
}
]
}GitHub targets should use immutable commit hashes or release tags whenever possible.
$env:CROSSREF_MAILTO="your-email@example.com"
uv run research-agent live-web-search `
--prompt "How should production agents recover from partial workflow failure?" `
--sources-config configs/live_sources.json `
--request-timeout 20 `
--traceThe command:
- validates the prompt and allowlist;
- creates one bounded asynchronous HTTP client;
- constructs all approved source adapters;
- routes sources by worker role;
- runs at most two workers concurrently;
- federates results while isolating provider failures;
- deduplicates scholarly evidence;
- screens evidence for obvious instruction attacks;
- prints worker results, provenance, URLs, risk flags, and traces.
The command is deterministic at the decision layer. It does not use Gemini to generate a narrative report.
uv run research-agent memory remember `
--user-id babu `
--session-id research-session-1 `
--kind research_interest `
"I research reliable multi-agent systems"uv run research-agent memory recall `
--user-id babu `
"What kind of agent systems do I research?"uv run research-agent memory forget `
--user-id babu `
MEMORY_ID_RETURNED_BY_REMEMBERMemory writes are rejected unless they satisfy the explicit policy. Retrieved provider data is converted back into application-owned memory models.
Evaluate Recall@k across dense, BM25, and hybrid retrieval:
uv run research-agent evaluate-retrieval `
--corpus examples/corpus `
--cases evals/retrieval_cases.json `
--top-k 2 `
--device cpuThe same stable chunk identifiers are used across ingestion and evaluation, allowing labeled retrieval cases to remain reproducible while the corpus remains unchanged.
uv run research-agent evaluate-agent `
--profile deterministic `
--trials 1 `
--suite evals/agent_tasks.json `
--corpus examples/corpus `
--device cpu `
--output evals/results/deterministicuv run research-agent evaluate-agent `
--profile deterministic `
--trials 1 `
--output evals/results/deterministic `
--write-baseline evals/baselines/deterministic.jsonuv run research-agent evaluate-agent `
--profile deterministic `
--trials 1 `
--baseline evals/baselines/deterministic.json `
--output evals/results/deterministic-regression$env:GEMINI_API_KEY="your-key"
uv run research-agent evaluate-agent `
--profile gemini `
--trials 1 `
--task-limit 3 `
--model gemini-2.5-flash `
--output evals/results/gemini-smokeEvaluation artifacts include:
report.json
summary.md
trajectories.jsonl
Measured properties include:
- trial pass rate;
- consistent task rate;
- pass@k;
- citation integrity;
- p95 latency;
- tool calls;
- model calls;
- nominal model cost;
- regression-gate status.
Run the complete test suite:
uv run pytest -vFormat and lint:
uv run ruff format src tests
uv run ruff check src testsRun static type checking:
uv run pyright src testsA CLI demonstration is not considered successful unless tests, linting, and type checking also pass.
Live provider tests should remain opt-in because external APIs are mutable:
$env:RUN_LIVE_SOURCE_TESTS="1"
$env:CROSSREF_MAILTO="your-email@example.com"
uv run pytest -v -m liveNormal unit tests use controlled HTTP transports and do not require network access.
Model output is treated as untrusted input.
The runtime validates:
- decision type;
- tool name;
- tool arguments;
- step budget;
- tool budget;
- worker budget;
- concurrency budget;
- timeout policy;
- retry policy;
- source authority.
A worker failure is represented as data so successful sibling work can remain available.
Cancellation is different: it represents orchestration control and must propagate rather than being disguised as an ordinary worker result.
Checkpoint recovery avoids repeating successful workers.
External side effects would additionally require idempotency keys because a timeout does not prove that the remote operation failed. The remote service may have completed the action before the response was lost.
Correct tool execution can still return irrelevant, outdated, incomplete, or misleading evidence.
Retrieval correctness and answer correctness are separate evaluation problems.
The external retrieval boundary enforces:
- HTTPS-only source URLs;
- explicit host allowlists;
- no automatic redirect trust;
- accepted content-type checks;
- maximum response sizes;
- bounded client timeouts;
- exact GitHub paths and refs;
- deterministic evidence identifiers;
- content hashes;
- prompt-injection risk flags;
- quarantine through
eligible_for_synthesis=False.
The risk scanner is a defense-in-depth mechanism, not a complete prompt-injection solution.
External content never receives authority to:
- modify the source allowlist;
- invoke shell commands;
- access secrets;
- select arbitrary tools;
- change runtime policy;
- create new external targets.
live-web-searchis controlled federated research, not an unrestricted search engine.- Documentation and web adapters fetch exact administrator-approved pages.
- The deterministic worker currently summarizes its highest-ranked eligible evidence rather than generating a full narrative literature review.
- Provider APIs, schemas, quotas, and availability can change.
- Regex-based injection detection cannot identify every adversarial instruction.
- Local word-window chunking is intentionally simple and is not document-layout aware.
- The project does not yet provide a graphical interface.
These limitations are explicit because trustworthy agent engineering requires knowing what a system does not guarantee.
- Provider-neutral interfaces over vendor coupling.
- Typed boundaries over loose dictionaries.
- Runtime authority over model authority.
- Deterministic infrastructure beneath probabilistic models.
- Bounded work over open-ended autonomy.
- Failure isolation without silent failure.
- Checkpointed state over implicit recovery.
- Explicit memory policy over automatic retention.
- Evidence provenance over unsupported generation.
- Evaluation gates over demo-driven confidence.