Minimal, debuggable agent framework for explicit pipelines and computation graphs.
Project description
ThinkAgain
ThinkAgain is a minimal, debuggable agent framework for building explicit pipelines and computation graphs. It captures execution plans before they run so you can reason about complex control flow without all the hidden state most orchestration libraries introduce.
Highlights
- Explicit control flow – compose workers with
>>, Switch, Conditional, Loop, and full computation graphs (including cycles). - Dual sync/async APIs – every worker can implement
__call__andacall, and pipelines/graphs mirror that with.run()and.arun(). - Deterministic state container – a single
Contextinstance flows through the system, carrying data, metadata, and an execution history you can inspect. - Debuggable by default – visualize the plan with
Pipeline.visualize()/Graph.to_dict(), or replay any run by readingctx.history. - Tiny mental model – just a handful of primitives plus Python; no DSL, runtime, or remote control plane.
Installation
Install the latest release from PyPI:
pip install thinkagain
To contribute or experiment against the local sources, use an editable install:
pip install -e .
Quick Start
from thinkagain import Context, Worker
class VectorDB(Worker):
def __call__(self, ctx: Context) -> Context:
ctx.documents = self.search(ctx.query)
ctx.log(f"Retrieved {len(ctx.documents)} docs")
return ctx
async def acall(self, ctx: Context) -> Context:
ctx.documents = await self.async_search(ctx.query)
ctx.log(f"Retrieved {len(ctx.documents)} docs")
return ctx
# Compose workers with >> and run synchronously
pipeline = vector_db >> reranker >> generator
ctx = pipeline.run(Context(query="What is ML?"))
# Or run the same pipeline asynchronously
ctx = await pipeline.arun(Context(query="What is ML?"))
print(ctx.answer)
print(ctx.history)
Build Workflows Your Way
Declarative pipelines
from thinkagain import Context
pipeline = retrieve >> rerank >> generate
ctx = pipeline.run(Context(query="agent evaluation"))
Branching and retries
from thinkagain import Switch, Loop
pipeline = (
retrieve
>> Switch(name="quality_check")
.case(lambda ctx: len(ctx.documents) >= 3, rerank)
.set_default(web_search >> rerank)
>> Loop(
name="refine_query",
condition=lambda ctx: ctx.quality < 0.8,
body=refine >> generate >> critique,
max_iterations=3,
)
>> generate
)
Graphs with cycles
from thinkagain import Graph, END, Context
graph = Graph(name="self_correcting_rag")
graph.add_node("retrieve", RetrieveWorker())
graph.add_node("generate", GenerateWorker())
graph.add_node("critique", CritiqueWorker())
graph.add_node("refine", RefineWorker())
graph.set_entry("retrieve")
graph.add_edge("retrieve", "generate")
graph.add_edge("generate", "critique")
graph.add_conditional_edge(
"critique",
route=lambda ctx: "done" if ctx.quality >= 0.8 else "refine",
paths={"done": END, "refine": "refine"},
)
graph.add_edge("refine", "retrieve") # Cycle!
result = graph.run(Context(query="What is ML?"))
Debugging & Introspection
Context.historyrecords every log message emitted by workers and control-flow nodes.ctx.to_dict()(or duck-typing withctx["key"]) exposes the exact state passed between stages.Pipeline.visualize()renders an ASCII tree;Graph.to_dict()gives a machine-readable plan.examples/graph_debugging.pyshows step-by-step execution and state inspection.
Examples
# Pipelines: sync + async + branching + retry loop
python examples/pipeline_examples.py
# Graphs with cycles / self-correcting RAG
python examples/graph_examples.py
# Interactive graph debugging walkthrough
python examples/graph_debugging.py
Documentation
See DESIGN.md for a deeper dive into the architecture, control-flow primitives, and future roadmap. The thinkagain/core package contains the minimal source code that powers everything in this repo.
License
ThinkAgain is distributed under the Apache 2.0 License (see LICENSE).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file thinkagain-0.1.0.tar.gz.
File metadata
- Download URL: thinkagain-0.1.0.tar.gz
- Upload date:
- Size: 20.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92de25cc241de945fb1f4204cf9b352d7db1edab3c12a4dee9b3d68a8a49108a
|
|
| MD5 |
378e7b91a53667ca2095bdb750494dae
|
|
| BLAKE2b-256 |
8df0b8efd9b4d1baf34e498dd176ab9385abe56db8061053c99256d313d99cef
|
Provenance
The following attestation bundles were made for thinkagain-0.1.0.tar.gz:
Publisher:
python-publish.yml on BDHU/thinkagain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
thinkagain-0.1.0.tar.gz -
Subject digest:
92de25cc241de945fb1f4204cf9b352d7db1edab3c12a4dee9b3d68a8a49108a - Sigstore transparency entry: 694084901
- Sigstore integration time:
-
Permalink:
BDHU/thinkagain@a970e6a36f8df23b863829c9b7e433b2406a1315 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/BDHU
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a970e6a36f8df23b863829c9b7e433b2406a1315 -
Trigger Event:
release
-
Statement type:
File details
Details for the file thinkagain-0.1.0-py3-none-any.whl.
File metadata
- Download URL: thinkagain-0.1.0-py3-none-any.whl
- Upload date:
- Size: 20.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36e009333cb89120e5674cf88c2d8b1bb15fe80cef3c78547fd29e46fb9af825
|
|
| MD5 |
cc7a57da141c0dac9ca2920db313b9a2
|
|
| BLAKE2b-256 |
8c2edacf68b3e6589e0d0a6a14e5992c45493bdf0c77712f49aa3c219dde0461
|
Provenance
The following attestation bundles were made for thinkagain-0.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on BDHU/thinkagain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
thinkagain-0.1.0-py3-none-any.whl -
Subject digest:
36e009333cb89120e5674cf88c2d8b1bb15fe80cef3c78547fd29e46fb9af825 - Sigstore transparency entry: 694085016
- Sigstore integration time:
-
Permalink:
BDHU/thinkagain@a970e6a36f8df23b863829c9b7e433b2406a1315 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/BDHU
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@a970e6a36f8df23b863829c9b7e433b2406a1315 -
Trigger Event:
release
-
Statement type: