A correct, simple, performant, and pythonic framework for building durable AI agents
Project description
PocketJoe
LLM Agents are just agents...
- Agents are policies
- A policy reasons over observations and chooses a batch of actions
- A policy can be any mix of LLM-based, human-in-the-loop, or heuristic
Semantics
An agent system using Reinforcement Learning theory with LLM semantics as first class
Policy: all code/logic/llm are policiesobservations- the set of observations for the policy to reason overoptions- a set of optional sub policies that the policy can chooseselected_actions- the set of concurrent actions the policy chose to takeMessage: a shared dataclass forobservationsandactionsthat aligns with llm semantics
LLM semantics as platform semantics
In LLM APIs, everything is a Message. We adopt this as our universal unit:
- Input:
observations: list[Message](what the policy sees) - Output:
selected_actions: list[Message](what the policy does)
Key insight: The runtime automatically invokes all option calls and injects the results back as observations. Your policy just returns requests; the platform handles execution.
Everything is a Policy
An LLM policy that can call other policies:
@policy_spec_mcp_tool(description="Calls OpenAI GPT-4 with tool support")
class OpenAILLMPolicy_v1(Policy):
async def __call__(self, observations: list[Message], options: list[str]) -> list[Message]:
"""LLM policy that calls OpenAI GPT-4 with tool support.
:param observations: List of Messages representing the conversation history + new input
:param options: Set of allowed options the LLM can call (policy names that will map to tools)
"""
response = await openai.chat.completions.create(
model="gpt-4",
messages=to_completions_messages(observations),
tools=to_completions_tools(self.ctx, options))
return map_response_to_messagess(response)
A simple heuristic policy:
@policy_spec_mcp_tool(description="Performs web search")
class WebSearchDdgsPolicy(Policy):
async def __call__(self, query: str) -> list[Message]:
"""
Performs a web search and returns results.
:param query: The search query string to search for
"""
results = DDGS().text(query, max_results=5)
results_str = "\n\n".join([f"Title: {r['title']}\nURL: {r['href']}\nSnippet: {r['body']}" for r in results])
return [Message(
actor=self.__class__.__name__,
type="action_result",
payload={"content": results_str}
)]
An orchestrator policy that coordinates LLM + search:
@policy_spec_mcp_tool(description="Orchestrator with LLM and search")
class SearchAgent(Policy):
ctx: "AppContext" # Override to specify context type
async def __call__(self, prompt: str) -> list[Message]:
"""
Orchestrator that gives the LLM access to web search.
:param prompt: The user prompt to process
"""
system_message = Message(actor="system", type="text",
payload={"content": "You are an AI assistant that can use tools to help answer user questions."})
prompt_message = Message(actor="user", type="text", payload={"content": prompt})
history = [system_message, prompt_message]
while True:
selected_actions = await self.ctx.llm(observations=history, options=["web_search"])
history.extend(selected_actions)
if not any(msg.type == "action_call" for msg in selected_actions):
break
return history
Use AppContext for registry (gives IDE type hints):
class AppContext(BaseContext):
def __init__(self, runner):
super().__init__(runner)
self.llm = self._bind(OpenAILLMPolicy_v1)
self.web_search = self._bind(WebSearchDdgsPolicy)
self.search_agent = self._bind(SearchAgent)
Enjoy:
async def main():
runner = InMemoryRunner()
ctx = AppContext(runner)
result = await ctx.search_agent(prompt="What is the latest Python version?")
print(f"\nFinal Result: {result[-1].payload['content']}")
Why this matters:
- Same interface for LLM, human, heuristic policies
- All policy parameters are optional (define what you need)
- Type-safe composition with IDE support
- Enables evolution: human → heuristic → LLM with no refactoring
A correct, simple, performant, and pythonic framework for building durable AI agents.
"There is no flow, only Policies and Actions."
Getting Started
Prerequisites
- Python 3.12+
uv(recommended)
Installation
uv sync
Running Examples
First, install with examples dependencies:
uv sync --extra examples
Search Agent (ReAct)
uv run python examples/search_agent.py
YouTube Summarizer
uv run python examples/youtube_summarizer.py
Dev Status
Still in prerelease, things will change
Intial version
- [] Tidy up code - add partly refactored code
- [] Proper tests
- [] Implement more examples from Pocket-Flow
Durable System:
- [] Ledger - Temporal style 'at least once, only one result' replay semantic
- [] Durable Storage wrapper - For long running tasks & replay
- [] Distrubuted - worker model
Background
Inspired by PocketFlow... I loved PocketFlow but it fell short in a couple of key areas. This is my rewrite that I can actually use.
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 pocket_joe-0.1.0.1.tar.gz.
File metadata
- Download URL: pocket_joe-0.1.0.1.tar.gz
- Upload date:
- Size: 68.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bbfe760c756a749da0f9eca286f2219d39c25e2fa42263741b749b309aa692ca
|
|
| MD5 |
71ce5be60786b196b9b11fa759b5e3ad
|
|
| BLAKE2b-256 |
3f6852f6a7c48543a0e4334da770a1d54cb41cd2bd906488436b825f7114979d
|
Provenance
The following attestation bundles were made for pocket_joe-0.1.0.1.tar.gz:
Publisher:
publish.yml on Sohojoe/pocket-joe
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pocket_joe-0.1.0.1.tar.gz -
Subject digest:
bbfe760c756a749da0f9eca286f2219d39c25e2fa42263741b749b309aa692ca - Sigstore transparency entry: 732257064
- Sigstore integration time:
-
Permalink:
Sohojoe/pocket-joe@04240d35cfe0d26fa407a4b0077623179f0ce6aa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Sohojoe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@04240d35cfe0d26fa407a4b0077623179f0ce6aa -
Trigger Event:
push
-
Statement type:
File details
Details for the file pocket_joe-0.1.0.1-py3-none-any.whl.
File metadata
- Download URL: pocket_joe-0.1.0.1-py3-none-any.whl
- Upload date:
- Size: 11.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 |
c9c1f46ff5e97faa504879af74035becacafc361993d1385497e225f4019f7f3
|
|
| MD5 |
786c1f01dbc4ecb7d0e18ba994a50b47
|
|
| BLAKE2b-256 |
1be8c916a323a80eeec0367036ea84726d714d1fcca0d446639aaa149c7e9b86
|
Provenance
The following attestation bundles were made for pocket_joe-0.1.0.1-py3-none-any.whl:
Publisher:
publish.yml on Sohojoe/pocket-joe
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pocket_joe-0.1.0.1-py3-none-any.whl -
Subject digest:
c9c1f46ff5e97faa504879af74035becacafc361993d1385497e225f4019f7f3 - Sigstore transparency entry: 732257066
- Sigstore integration time:
-
Permalink:
Sohojoe/pocket-joe@04240d35cfe0d26fa407a4b0077623179f0ce6aa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Sohojoe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@04240d35cfe0d26fa407a4b0077623179f0ce6aa -
Trigger Event:
push
-
Statement type: