Skip to main content

petfishFramework — a general AI Agent framework

Project description

petfishFramework

A lightweight Python framework for reliable, auditable, budget-aware, and permission-aware AI agents.

Python 3.10+ License: MIT Tests: 187

Status: Alpha — API may change. Core runtime works; see Roadmap.

Quick Start (Zero Cost — No API Key)

pip install petfishframework
from petfishframework import Agent, ReAct
from petfishframework.tools.calculator import Calculator
from petfishframework.models.fake import FakeModel

# FakeModel — runs without any API key, perfect for testing
model = FakeModel.script_tool_then_answer(
    tool_name="calculator",
    tool_args={"expression": "17 * 23"},
    final_answer="391",
)

agent = Agent(
    model=model,
    reasoning=ReAct(),
    tools=(Calculator(),),
)

result = agent.run("What is 17 * 23?")
print(result.answer)  # "391"
print(result.usage.total_tokens)
print(len(result.trajectory.steps), "steps")

Quick Start (Real LLM)

pip install "petfishframework[openai]"
from petfishframework import Agent, ReAct
from petfishframework.tools.calculator import Calculator
from petfishframework.models.openai import OpenAIModel

agent = Agent(
    model=OpenAIModel(model="gpt-4o-mini"),  # or model="openai:gpt-4o-mini"
    reasoning=ReAct(),
    tools=(Calculator(),),
)

result = agent.run("What is 17 * 23?")
print(result.answer)  # "391"

Set OPENAI_API_KEY in .env or environment. Works with OpenAI-compatible APIs (SiliconFlow, etc.) via OPENAI_BASE_URL.

Budget Control (Runtime Hard Limits)

from petfishframework import Budget

# Budget is execution-scoped — pass to run() or session(), not Agent()
result = agent.run(
    "Complex calculation task",
    budget=Budget(max_tokens=1000, max_tool_calls=5, max_steps=10),
)
# Exceeding any limit raises BudgetExceeded

Permission Gate (Runtime Access Control)

from petfishframework.permissions.model import (
    Decision, DecisionEffect, PermissionPolicy,
)

class DenyExpensiveTools:
    """Custom policy: deny tools tagged 'expensive'."""
    def evaluate(self, subject, action, resource, context):
        if "expensive" in resource.tags:
            return Decision(effect=DecisionEffect.DENY, reason="too expensive")
        return Decision(effect=DecisionEffect.ALLOW)

agent = Agent(
    model=model,
    reasoning=ReAct(),
    tools=(Calculator(),),
    permission_policy=DenyExpensiveTools(),
)
# Tool calls pass through the Environment chokepoint — denied calls never execute

Replay & Audit (Event-Sourced Sessions)

session = agent.session("What is 17 * 23?")
result = session.run()

# Every step is recorded — model calls, tool calls, permission decisions
for event in session.replay():
    print(f"{event.type}: {event.data}")

# Events come from session.replay(), not from Result
# Result has: answer, usage, trajectory
# Session has: events, replay(), checkpoint()

Core Concepts

Concept Role
Agent Immutable recipe (model + reasoning + tools)
Session Event-sourced execution (auditable, replayable)
Environment Single chokepoint (all calls audited, budget-metered, permission-gated)
Budget Hard execution limits (tokens, cost, steps, tool calls)
Permission SARC access control with 6 DecisionEffects
Replay AUDIT (event log), RESUME (checkpoint), RERUN (fresh)
Pass^k Reliability metric (k repetitions + perturbation suite)

Features

  • 3 reasoning strategies: ReAct, LATS (MCTS search), LLM+P (symbolic planning)
  • 3 model adapters: OpenAI, Anthropic, FakeModel (deterministic testing)
  • 3 routing axes: ToolRegistry (auto tool selection), Adaptive-RAG (retrieval), ReasoningStrategy
  • MCP client: real stdio transport, tool discovery from external MCP servers
  • Multi-agent: AgentAsTool (supervisor delegates to specialist agents)
  • Structured output: JSON → dataclass (zero regex scoring)
  • Conversation memory: cross-session recall via ConversationStore
  • Async + streaming: dual sync/async interface

Documentation

Roadmap

  • v0.1.x (current): Core runtime works, quickstart verified ✅
  • v0.2.x: Enterprise agent examples, structured audit reports
  • v0.3.x: Policy engine (YAML), MASK enforcement, credential broker
  • v0.4.x: Production hardening, deployment guides

Development

git clone https://github.com/kylecui/petfishFramework.git
cd petfishFramework
uv sync --all-extras
uv run pytest              # 187 tests
uv run ruff check src/ tests/

See CONTRIBUTING.md for details.

License

MIT — © 2026 Kyle Cui

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

petfishframework-0.1.3.tar.gz (283.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

petfishframework-0.1.3-py3-none-any.whl (73.3 kB view details)

Uploaded Python 3

File details

Details for the file petfishframework-0.1.3.tar.gz.

File metadata

  • Download URL: petfishframework-0.1.3.tar.gz
  • Upload date:
  • Size: 283.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for petfishframework-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a31e99d1884cc9e8e3b1f3161e1a8f7c4fb58ce78059e4a5f60cd20f228b0f93
MD5 541b21cea4ab473b59a1efcc352ee278
BLAKE2b-256 45b3ed6982b0ceb392a5db35da9cffe48e42c16cdd64debc66902c320caf31c7

See more details on using hashes here.

File details

Details for the file petfishframework-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for petfishframework-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c8b24de1531fc89af65b227cbdc16a1ee45d4bd1460529941fa72ca213367b36
MD5 56491abc963ab77e170ac6bf927c527c
BLAKE2b-256 133e66553ff82f8126f4c4e6a0eeae50e83575ce917efead26ba6724bc7ceab9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page