Plug-and-play async context re-entry for LangGraph agents
Project description
Async Context Engine
Plug-and-play async context re-entry for LangGraph agents.
Dispatch long-running tasks to external systems, let the user keep chatting, and deliver results back into the conversation automatically — without blocking.
The Problem
LangGraph agents are synchronous. When a task takes 10 seconds or 5 minutes, you have two bad options: block the user, or lose the result. This library gives you a third option: dispatch, continue, re-enter.
How It Works
1. User asks for something slow → Your graph dispatches the task
2. Library tracks it in a TaskStore → User keeps chatting normally
3. External system finishes work → Calls update_task_result()
4. Built-in poller detects it → Re-enters the graph automatically
5. Result appears in conversation → Without the user asking again
Install
pip install async-context-engine
# Or with uv (recommended):
uv add async-context-engine
Quick Start
1. Extend your state:
from async_context_engine import AsyncTaskState
class MyState(AsyncTaskState):
messages: Annotated[list[dict], operator.add]
2. Dispatch tasks in your graph:
from async_context_engine import dispatch_task
def dispatcher(state, config):
task = dispatch_task(store, config["configurable"]["thread_id"], "calculate total")
my_system.run(task.task_id, "calculate total") # Send to your worker
return {"messages": [...], "task_records": {task.task_id: task}}
3. Report results from your external system:
from async_context_engine import update_task_result
update_task_result(store, task_id="abc-123", result="$1,250")
4. Start the poller:
from async_context_engine import AsyncPoller
poller = AsyncPoller(store=store, graph=graph, config=config, interval=5, on_result=display)
poller.start()
That's it. Results flow back into the conversation automatically.
What You Build vs. What the Library Handles
| You | Library |
|---|---|
| Your LangGraph graph (nodes, edges, LLM) | Task ID generation |
| Decide what's async (classifier) | Task persistence (TaskStore) |
| Execute the actual work (sub-agents, APIs) | Background polling |
Call dispatch_task() and update_task_result() |
Graph re-entry with results |
Display output (on_result callback) |
Deduplication (each result delivered once) |
Documentation
Developer Guide — Comprehensive walkthrough of every concept, the full API reference, architecture diagrams, and step-by-step integration instructions.
Shipped Components
| Component | Description |
|---|---|
TaskRecord |
Dataclass representing a tracked task |
TaskStore |
ABC for pluggable persistence |
InMemoryTaskStore |
Dict-backed store for tests |
FileTaskStore |
JSON file store for prototyping |
AsyncTaskState |
LangGraph state mixin (extend this) |
dispatch_task() |
Create a pending task in the store |
update_task_result() |
Mark a task complete/failed (called from external systems) |
has_pending_results() |
Check if results are waiting in state |
AsyncPoller |
Background thread that polls and re-enters the graph |
Running the Example
git clone https://github.com/sagarmainkar/async-context-engine.git
cd async-context-engine
# Install everything (library + example dependencies)
uv sync --extra examples
# Start Ollama (required for the example LLM)
ollama serve
# Run the demo
cd examples/basic
uv run runner.py
No venv creation needed.
uv synccreates the.venvautomatically, resolves all dependencies, and installs the library in editable mode — one command, everything works.
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 async_context_engine-0.1.0.tar.gz.
File metadata
- Download URL: async_context_engine-0.1.0.tar.gz
- Upload date:
- Size: 12.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
197ebee9b6818b672663cb1f17bebe397895a854f73f1a936ca0f77a0a5ddfc7
|
|
| MD5 |
c177382d6515b031a4dd2802f1c73053
|
|
| BLAKE2b-256 |
e014dd7dc4efa68584583443d1a12d01c442abeb3846047af8999ac823f68c61
|
Provenance
The following attestation bundles were made for async_context_engine-0.1.0.tar.gz:
Publisher:
publish.yml on sagarmainkar/async-context-engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_context_engine-0.1.0.tar.gz -
Subject digest:
197ebee9b6818b672663cb1f17bebe397895a854f73f1a936ca0f77a0a5ddfc7 - Sigstore transparency entry: 1006497095
- Sigstore integration time:
-
Permalink:
sagarmainkar/async-context-engine@8af3ab6a8f3f82a3ac3beee0e5d1cd96426f1c0b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sagarmainkar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8af3ab6a8f3f82a3ac3beee0e5d1cd96426f1c0b -
Trigger Event:
release
-
Statement type:
File details
Details for the file async_context_engine-0.1.0-py3-none-any.whl.
File metadata
- Download URL: async_context_engine-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.6 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 |
cb46b19cf2e2df46f32579c6ac1620d2a7f15f13ae577d8cc3484fc693a4e10e
|
|
| MD5 |
6b19c0214a2737ec13c42923cd9a952b
|
|
| BLAKE2b-256 |
1a4dc9cfb55d17e97863a67d64d66e1bba52e1bb492c2a07b327fc8c44d6f4cf
|
Provenance
The following attestation bundles were made for async_context_engine-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on sagarmainkar/async-context-engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
async_context_engine-0.1.0-py3-none-any.whl -
Subject digest:
cb46b19cf2e2df46f32579c6ac1620d2a7f15f13ae577d8cc3484fc693a4e10e - Sigstore transparency entry: 1006497096
- Sigstore integration time:
-
Permalink:
sagarmainkar/async-context-engine@8af3ab6a8f3f82a3ac3beee0e5d1cd96426f1c0b -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/sagarmainkar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8af3ab6a8f3f82a3ac3beee0e5d1cd96426f1c0b -
Trigger Event:
release
-
Statement type: