Incremental engine for long horizon agents π Star if you like it!
Rust agentic-data-frameworkaiai-agentschange-data-capturecodebase-intelligencecontext-engineeringdata-engineeringdata-indexingdata-processingetlhelp-wantedindexingknowledge-graphllmlong-horizon-agentpythonragreal-timerustsemantic-search
fix(examples): CocoIndex Agents runs from its README (#2790)
Jiangzhou4eab410d0b5e
diff --git a/examples/cocoindex_agents/README.md b/examples/cocoindex_agents/README.mdindex 1e1b94f4..1b1f3855 100644--- a/examples/cocoindex_agents/README.md+++ b/examples/cocoindex_agents/README.md@@ -17,6 +17,50 @@ what they measured: the same decomposition in three drives of each flow, nomodel call on an unchanged rerun, and two or three calls after one editedinput.+## Running++It runs on the CocoIndex in this repository: it uses APIs no release has+yet, so install it from a clone, not from PyPI. Once, from the repository+root:++```sh+uv run maturin develop # build CocoIndex from this checkout+uv sync --extra litellm --inexact # the model client+uv pip install --no-deps -e examples/cocoindex_agents # this package, into the same environment+```++Keep `--inexact` on later syncs: a plain `uv sync` removes the last install.++The model is `openai/gpt-6.1-terra`, or the LiteLLM model named in+`$LLM_MODEL`. Put that provider's key in the environment, for example+`export OPENAI_API_KEY=...`.++Then go to the folder your prompt is about and describe the outcome you want.+Paths in the prompt are relative to that folder:++```sh+cd ~/my-project+uv run --project ~/src/cocoindex python -m cocoindex_agents.app \+ "Summarize every markdown file under ./docs. Write one summary per file into ./out,+ named after the source file with .md replaced by .summary.md.+ Answer with one line saying what was written."+```++Replace `~/src/cocoindex` with your clone. The command prints CocoIndex's+update report, then the answer. It keeps its state in `./.coco_db`, or in+`$COCOINDEX_DB` when that is set. Run the same command again: when nothing+changed it makes no model call, and after you edit one file only that file's+work runs again. Delete `.coco_db` to start from scratch.++Two more ways to run it:++- **The sample flows** under `flows/` come with their data, and their runner+ adds `--stats` for cache usage and `--plan` for the plan it chose:+ `uv run python examples/cocoindex_agents/flows/run.py summaries --stats`.+ See [`flows/README.md`](flows/README.md).+- **A Google Drive folder** of your own, read as your account after a one-time+ sign-in: see *The `drive` flow* in [`flows/README.md`](flows/README.md).+## Layout- `cocoindex_agents/` β the package (see DESIGN.md Β§9 for the module map, Β§8 for@@ -37,10 +81,6 @@ From the repository root, after `uv run maturin develop`:uv run pytest examples/cocoindex_agents/tests```-Or as a standalone project:--```sh-cd examples/cocoindex_agents-uv sync --group dev-uv run pytest-```+The tests need no API key. They also need this repository's CocoIndex, so+there is no standalone install yet: `uv sync` inside this directory would+take the last CocoIndex release from PyPI, which lacks APIs this package uses.diff --git a/examples/cocoindex_agents/cocoindex_agents/app.py b/examples/cocoindex_agents/cocoindex_agents/app.pyindex 44a48ba6..2230d05b 100644--- a/examples/cocoindex_agents/cocoindex_agents/app.py+++ b/examples/cocoindex_agents/cocoindex_agents/app.py@@ -1,8 +1,11 @@"""Assemble an app: default roles + built-in tools, and build a ``coco.App`` for a flow prompt.-Usage:+Usage, from the folder the prompt talks about (README.md, *Running*):- LLM_MODEL=openai/gpt-6.1-terra python -m cocoindex_agents.app "For every .md under ./docs, ..."+ python -m cocoindex_agents.app "For every .md under ./docs, ..."++``$LLM_MODEL`` picks the model, and the run's state is kept in ``$COCOINDEX_DB``,+else ``./.coco_db``.The sample flows under ``flows/`` drive this with checked-in data."""@@ -10,6 +13,7 @@ The sample flows under ``flows/`` drive this with checked-in data.from __future__ import annotationsimport os+import pathlibimport sysimport cocoindex as coco@@ -18,6 +22,7 @@ from .litellm_client import LiteLLMClientfrom .model import MODEL_CLIENTfrom .roles import default_rolesfrom .session import run_open_session+from .spec import SessionResultfrom .tools import (AGENTS_CONFIG,AgentsConfig,@@ -66,7 +71,7 @@ def build_app(env: coco.Environment,config: AgentsConfig,scratch: SessionScratch | None = None,-) -> coco.App[..., object]:+) -> coco.App[..., SessionResult]:"""One app per flow. The orchestrator is an open session: skipped while what it read is unchanged.``scratch`` is marked when the orchestrator's body runs; left untouched,@@ -91,13 +96,18 @@ def main(argv: list[str] | None = None) -> int:# LiteLLM's aiohttp transport leaves a pending close task at interpreter# exit ("Task was destroyed but it is pending"); httpx does not.litellm.disable_aiohttp_transport = True- env = coco.Environment(coco.Settings.from_env())+ # ``Settings.from_env`` does not read ``COCOINDEX_DB``; the default state+ # directory sits beside the data, as the sample flows keep theirs.+ db_path = pathlib.Path(os.environ.get("COCOINDEX_DB") or ".coco_db")+ env = coco.Environment(coco.Settings.from_env(db_path=db_path))config = default_config(os.environ.get("LLM_MODEL", DEFAULT_MODEL))env.context_provider.provide(MODEL_CLIENT, LiteLLMClient())env.context_provider.provide(AGENTS_CONFIG, config)app = build_app("cocoindex_agents", " ".join(args), env=env, config=config)result = app.update_blocking(report_to_stdout=True)- print(result)+ # A list only in preview mode, which this run is not.+ assert isinstance(result, SessionResult)+ print(result.answer)return 0