phoson-engine-minimal
Minimal Python runtime for the Phoson autonomous-agent platform
๐ฅ Open Source โ Built for developers who want full control over their AI agents.
๐ Table of Contents
- What this project is
- Why Phoson?
- Features
- High-level architecture
- Repository map
- Core modules
- ๐ Quick Start
- Installation
- Development setup
- Run checks locally
- Environment variables
- Usage examples
- CI and security workflows
- Commit message format
- Roadmap
- Contributing
- License
- Support
๐ค What this project is
phoson-engine-minimal is the core runtime behind the Phoson autonomous-agent platform. It's a lightweight, framework-free Python implementation that gives you complete control over your AI agents without the bloat of heavy frameworks.
Unlike other agent frameworks (LangChain, LangGraph, etc.), Phoson is built from scratch using provider SDKs directly, with a custom ReAct loop designed for:
- ๐ Streaming behavior โ Token-by-token events for real-time UIs
- ๐ง Tool-call orchestration โ Full control over tool execution
- ๐ฐ Cost accounting โ Track spend per run with built-in pricing
- ๐๏ธ Observability โ
RunStepevents and typed event streams - ๐ณ Session trees โ Branchable conversation history (not linear!)
- โจ๏ธ Interactive REPL โ Debug and iterate on agents interactively
๐ฏ Why Phoson?
| Traditional Frameworks | Phoson |
|---|---|
| Heavy dependencies | Zero external agent frameworks |
| Linear conversations | Branchable conversation trees |
| Black-box streaming | Full event visibility |
| Fixed patterns | Custom ReAct loop |
| Enterprise pricing | MIT licensed |
โจ Features
| Feature | Description |
|---|---|
| Framework-free | Pure Python + provider SDKs; no LangChain/LangGraph |
| Multi-provider | OpenAI, Anthropic, OpenRouter, Ollama support |
| Typed events | Normalized LLMEvent stream for all providers |
| Tool execution | @tool decorator with JSON Schema definitions |
| Middleware hooks | Pre/post processing for LLM calls and tool execution |
| Branching sessions | ConversationTree for non-linear conversation history |
| Interactive REPL | CLI with streaming, branching, and model switching |
| Cost tracking | Built-in pricing module for USD usage calculation |
| Thinking support | Native reasoning/thinking token handling (Anthropic & OpenAI o1) |
๐๏ธ High-level architecture
flowchart LR
U[App / CLI / API] --> AE[AgentEngine\nphoson_agent]
AE --> MW[Middleware Hooks]
AE --> T[Registered Tools]
AE --> S[ConversationTree + Storage]
AE --> C[BaseLLMChat Contract]
C --> OA[OpenAIChat]
C --> AN[AnthropicChat]
OA --> P1[OpenAI / OpenRouter / Ollama]
AN --> P2[Anthropic]
OA --> E[Typed LLM Events]
AN --> E
E --> AE
AE --> R[Agent Events + RunResult]
Runtime loop (tool call cycle)
sequenceDiagram
participant Client
participant Engine as AgentEngine
participant LLM as LLM Adapter
participant Tool as Tool Handler
Client->>Engine: run(messages, config)
Engine->>LLM: stream(history, config, tools)
LLM-->>Engine: TokenEvent / ReasoningTokenEvent
LLM-->>Engine: ToolCallEvent
Engine->>Tool: execute(args)
Tool-->>Engine: result/error
Engine->>LLM: continue with ToolResultBlock
LLM-->>Engine: UsageEvent + LLMDoneEvent
Engine-->>Client: AgentRunResult
๐บ๏ธ Repository map
phoson-engine-minimal/
โโโ phoson_llm/ # LLM normalization layer (adapters + schemas + pricing)
โโโ phoson_agent/ # ReAct agent loop, tools, middleware, sessions
โโโ phoson_cli/ # Interactive CLI (REPL) for agent sessions
โโโ tests/ # Unit/integration tests for llm and agent layers
โโโ .github/workflows/ # CI and security automation
โโโ PROJECT.md # Deep architecture notes and roadmap
โโโ pyproject.toml # Project metadata, dependencies, tooling config
๐ฆ Core modules
phoson_llm โ LLM normalization layer
Provider adapters return a single typed event stream (LLMEvent subclasses):
| Event | Description |
|---|---|
LLMStartEvent |
Call start (model, message count) |
TokenEvent |
Text fragment token-by-token |
ReasoningStartEvent |
Model started reasoning (Anthropic thinking / OpenAI o1) |
ReasoningTokenEvent |
Reasoning fragment |
ReasoningDoneEvent |
Complete reasoning block |
ToolCallDeltaEvent |
Partial tool args chunk (for real-time UI) |
ToolCallEvent |
Complete tool call with parsed args |
UsageEvent |
Tokens + cost in USD |
LLMDoneEvent |
Full assembled text (always last) |
ErrorEvent |
Error with code, message, retryable flag |
Supported providers:
- Anthropic โ
AnthropicChat(thinking, tool use, prompt caching) - OpenAI โ
OpenAIChat(tool use, reasoning_effort for o1/o3) - OpenRouter โ
OpenAIChat(base_url=..., api_key=...) - Ollama โ
OpenAIChat(base_url="http://localhost:11434/v1", api_key="ollama")
Pricing module (phoson_llm.pricing) provides calculate_cost() for provider-level USD usage.
phoson_agent โ Agent orchestration
Stateless-by-run orchestration over message history with tool execution:
AgentEngineโ Main entry point for running agents (async and sync)@tooldecorator โ Transform Python functions intoAgentTooldefinitions with JSON SchemaAgentMiddlewareโ Hooks for pre/post processing (LLM calls, tool execution)AgentContextโ Shared state across middleware and tools
phoson_agent.sessions โ Conversation persistence
ConversationTreeโ Branchable conversation structure (not linear)ConversationNodeโ Individual node with messages, children, labelJsonlStorageโ JSONL-backed session storage (local file)SessionMetaโ Session metadata (id, message_count, created_at, updated_at)
phoson_cli โ Interactive REPL
Command-line interface for interactive agent sessions:
PhosonReplโ Interactive read-eval-print loop- Commands:
/exit,/quit,/clear,/new,/model,/tree,/sessions,/branch,/label,/help - Real-time streaming responses
- Session branching and labeling
- Multiple model switching
๐ Quick Start
from phoson_agent import AgentEngine
from phoson_llm.chats.openai import OpenAIChat
from phoson_llm.schemas import Message, ModelConfig
engine = AgentEngine(
chat=OpenAIChat(),
tools=[],
phoson_weight=1.2,
)
result = engine.run_sync(
messages=[Message(role="user", content="Summarize this project in one line")],
config=ModelConfig(model="openai/gpt-4o-mini", max_tokens=128),
)
print(result.final_content)
print(result.total_cost_usd, result.total_credits)
Or run the interactive CLI:
uv run phoson-cli
Run the setup wizard to configure provider credentials and defaults:
uv run phoson-cli --setup
๐ฅ Installation
# Clone the repository
git clone https://github.com/phoson-lat/phoson-engine-minimal.git
cd phoson-engine-minimal
# Install dependencies
uv sync --dev --locked
# Install git hooks
uv run pre-commit install --install-hooks
uv run pre-commit install --hook-type commit-msg
uv run pre-commit install --hook-type pre-push
๐ ๏ธ Development setup
Install dependencies
uv sync --dev --locked
Install git hooks
uv run pre-commit install --install-hooks
uv run pre-commit install --hook-type commit-msg
uv run pre-commit install --hook-type pre-push
โ Run checks locally
uv run ruff format --check .
uv run ruff check .
uv run python -m compileall phoson_llm phoson_agent phoson_cli
uv run pytest -q
๐ Environment variables
ANTHROPIC_API_KEY=
OPENAI_API_KEY=
OPENROUTER_API_KEY=
Note: Use
OPENROUTER_API_KEYwhen initializingOpenAIChatwith an OpenRouterbase_url.
๐ป Usage examples
Minimal agent usage
from phoson_agent import AgentEngine
from phoson_llm.chats.openai import OpenAIChat
from phoson_llm.schemas import Message, ModelConfig
engine = AgentEngine(
chat=OpenAIChat(),
tools=[],
phoson_weight=1.2,
)
result = engine.run_sync(
messages=[Message(role="user", content="Summarize this project in one line")],
config=ModelConfig(model="openai/gpt-4o-mini", max_tokens=128),
)
print(result.final_content)
print(result.total_cost_usd, result.total_credits)
Define a tool
from phoson_agent import tool
@tool
def calculate(expression: str) -> str:
"""Evaluate a mathematical expression."""
return str(eval(expression))
Interactive CLI
uv run phoson-cli
Available commands:
/newโ Start a new session/model <name>โ Switch model/treeโ Show conversation tree/sessionsโ List saved sessions/branchโ Branch from current node/label <text>โ Label current node/helpโ Show all commands
๐ CI and security workflows
.github/workflows/ci.yml: Format check, lint, smoke compile, and tests on PRs and pushes tomain..github/workflows/security.yml: Dependency audit and secret scan on PRs, pushes tomain, and weekly schedule.
๐ Commit message format
Conventional Commits are enforced through a commit-msg hook.
Examples:
feat: add streaming chat abstraction
fix: handle unknown model pricing fallback
chore: update pre-commit hook versions
Common types: feat, fix, docs, refactor, test, chore, ci
๐๏ธ Roadmap
For detailed architecture notes and future plans, see PROJECT.md.
๐ค Contributing
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'feat: add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
Please read CONTRIBUTING.md for details on our code of conduct and development process.
Ideas for contributions
- ๐ Add new LLM providers (Google Gemini, Azure OpenAI, etc.)
- ๐ง Improve tool execution (batching, retries, caching)
- ๐ Add observability integrations (OpenTelemetry, Langfuse)
- ๐ฅ๏ธ Build a web-based REPL or playground
- ๐ Improve documentation and examples
๐ License
This project is licensed under the MIT License โ see the LICENSE file for details.
MIT License
Copyright (c) 2024 Phoson
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
๐ฌ Support
- Issues: GitHub Issues for bug reports
- Discussions: GitHub Discussions for questions
- Documentation: See PROJECT.md for deep architecture notes
- Website: https://phoson.lat
- SDK Docs: https://phoson.lat/docs
โญ Show your support
Give us a โญ๏ธ if this project helped you build better AI agents!
Built with ๐ฅ by phoson.lat
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 phoson_engine_minimal-0.3.0.tar.gz.
File metadata
- Download URL: phoson_engine_minimal-0.3.0.tar.gz
- Upload date:
- Size: 360.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63961105a538c34eae13b2174e25dce2c2fc5a9d8932f979e96d6da7de5ee9cd
|
|
| MD5 |
fb93c3ad24ceadd10643cba7ad11bd4a
|
|
| BLAKE2b-256 |
ee06c3e03d4a69d21677ef05eaed5e550ba9f31b9db956146ae6ba4c298d6d1c
|
Provenance
The following attestation bundles were made for phoson_engine_minimal-0.3.0.tar.gz:
Publisher:
publish.yml on phoson-lat/phoson-engine-minimal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
phoson_engine_minimal-0.3.0.tar.gz -
Subject digest:
63961105a538c34eae13b2174e25dce2c2fc5a9d8932f979e96d6da7de5ee9cd - Sigstore transparency entry: 2404736453
- Sigstore integration time:
-
Permalink:
phoson-lat/phoson-engine-minimal@5098961ffd09985418250e1e0b9597c9604f4f75 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/phoson-lat
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5098961ffd09985418250e1e0b9597c9604f4f75 -
Trigger Event:
release
-
Statement type:
File details
Details for the file phoson_engine_minimal-0.3.0-py3-none-any.whl.
File metadata
- Download URL: phoson_engine_minimal-0.3.0-py3-none-any.whl
- Upload date:
- Size: 175.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d02c0e9a67496be2bd80f32ac39e62e8230bf99b6f52724d402ff08b8c322c25
|
|
| MD5 |
9618a4a06990d54ad2cd3850e14b295d
|
|
| BLAKE2b-256 |
6c8e0b5347165dba8d7f88b6274263c8593c922598765329acf954b60a5cb8f2
|
Provenance
The following attestation bundles were made for phoson_engine_minimal-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on phoson-lat/phoson-engine-minimal
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
phoson_engine_minimal-0.3.0-py3-none-any.whl -
Subject digest:
d02c0e9a67496be2bd80f32ac39e62e8230bf99b6f52724d402ff08b8c322c25 - Sigstore transparency entry: 2404736894
- Sigstore integration time:
-
Permalink:
phoson-lat/phoson-engine-minimal@5098961ffd09985418250e1e0b9597c9604f4f75 -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/phoson-lat
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5098961ffd09985418250e1e0b9597c9604f4f75 -
Trigger Event:
release
-
Statement type: