iris-next
Project description
IrisAgent
最小化的智能体框架,基于 openai-agents-python 和 loom-agent 的核心设计理念。
核心特性
✅ 已实现
-
Pydantic 增强的工具系统
- 支持复杂嵌套参数(List[str], BaseModel)
- 自动类型校验和反序列化
- 自动生成 JSON Schema
- 工具安全属性(read_only, destructive)
- 工具速率限制(rate_limit)
-
多智能体交接 (Handoff)
- 原生支持 Agent 之间的动态切换
- 保留上下文无缝交接
- 类似 OpenAI Agents SDK 的 Handoff 机制
-
沙盒隔离 (Sandbox)
- 抽象 Sandbox 接口
- LocalSandbox 实现
- 为危险工具提供隔离执行环境
-
分层流式输出
- 原始事件流(RawLLMEvent)
- LLM Token 流
- 工具调用入参流
- 工具执行状态流
- 工具结果流
- Handoff 事件流
-
工具治理
- 权限检查
- 自动重试
- 超时控制
- 速率限制(防止滥用)
-
智能上下文压缩
- 基于阈值的自动压缩
- 保留重要消息
-
Skill 动态加载
- 从文件/目录加载
- 自动注册工具
-
Usage 统计
- Token 消耗跟踪
- 按 Agent 分组统计
- 成本估算支持
-
Hook 系统
- before_run / after_run
- before_tool_call / after_tool_call
- on_error / on_handoff
-
完善的异常体系
- 语义化异常类型
- 区分可恢复/不可恢复错误
架构设计
src/iris_agent/
├── agent.py # Agent 配置
├── run.py # Runner 执行引擎
├── tool.py # 工具系统(Pydantic + 安全属性)
├── tool_executor.py # 工具执行器(权限 + 速率限制)
├── handoff.py # Handoff 机制
├── exceptions.py # 异常体系
├── usage.py # Token 使用统计
├── hooks.py # 生命周期钩子
├── context/ # 上下文管理
├── sandbox/ # 沙盒抽象
├── streaming/ # 分层流式事件
├── skill/ # 技能加载
└── types/ # 类型定义
快速开始
安装
pip install -r requirements.txt
环境变量配置
export OPENAI_API_KEY=your-api-key
export OPENAI_BASE_URL=http://localhost:11434/v1
基础使用
from iris_agent import Agent, Runner, tool, ToolRegistry
@tool(name="calculator", description="Calculate")
def calculator(expression: str) -> str:
return str(eval(expression))
registry = ToolRegistry()
registry.register(calculator._tool_config)
agent = Agent(
name="math_agent",
instructions="You are a math assistant.",
tool_registry=registry
)
runner = Runner(agent)
async for event in runner.run("What is 123 * 456?"):
if event.type.value == "llm_token":
print(event.token, end="")
Pydantic 复杂参数
from pydantic import BaseModel
from iris_agent import tool
class SearchParams(BaseModel):
query: str
filters: list[str]
limit: int = 10
@tool(name="search", description="Search with filters")
def search(params: SearchParams) -> str:
return f"Searching: {params.query}, filters: {params.filters}"
多智能体 Handoff
from iris_agent import Agent, Handoff, Runner
specialist = Agent(name="specialist", instructions="...")
generalist = Agent(
name="generalist",
instructions="...",
handoffs=[
Handoff(
target_agent=specialist,
description="Transfer to specialist for complex queries"
)
]
)
runner = Runner(generalist)
# Agent 会自动切换
新特性使用示例
工具安全属性
from iris_agent import tool
@tool(
name="delete_file",
description="Delete a file",
destructive=True, # 标记为破坏性操作
requires_permission=True
)
def delete_file(path: str) -> str:
return f"Deleted {path}"
@tool(
name="read_file",
description="Read a file",
read_only=True, # 只读工具
requires_permission=False
)
def read_file(path: str) -> str:
return f"Content of {path}"
@tool(
name="api_call",
description="Call external API",
rate_limit=10 # 限制每分钟10次调用
)
def api_call(endpoint: str) -> str:
return f"Called {endpoint}"
Usage 统计
from iris_agent import Agent, Runner, UsageTracker
tracker = UsageTracker()
agent = Agent(name="assistant", instructions="...")
runner = Runner(agent)
# 运行后获取统计
async for event in runner.run("Hello"):
pass
# 记录使用(需在 Runner 中集成)
# tracker.record("assistant", Usage(prompt_tokens=100, completion_tokens=50))
print(tracker.get_summary())
Hook 系统
from iris_agent import Agent, Runner, Hooks
async def log_before_tool(tool_name: str, args: dict):
print(f"Calling tool: {tool_name} with {args}")
async def log_after_tool(tool_name: str, result):
print(f"Tool {tool_name} returned: {result}")
hooks = Hooks()
hooks.before_tool_call.append(log_before_tool)
hooks.after_tool_call.append(log_after_tool)
# 在 Runner 中使用(需集成到 Runner)
依赖
- openai >= 1.0.0
- pydantic >= 2.0.0
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
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 iris_next-0.0.4.tar.gz.
File metadata
- Download URL: iris_next-0.0.4.tar.gz
- Upload date:
- Size: 21.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92d60f75fa980df8aba32f41d1d146f34d55641dfa5586b90498fe55750d53ff
|
|
| MD5 |
12587268bde0f024ea15718d4da0ea42
|
|
| BLAKE2b-256 |
8c44f1f52fd41a2e03252b76f9549a5f1d2ef15af6fe26a2294cb4fbd03f1666
|
Provenance
The following attestation bundles were made for iris_next-0.0.4.tar.gz:
Publisher:
publish.yml on xxWeiDG/iris-next
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
iris_next-0.0.4.tar.gz -
Subject digest:
92d60f75fa980df8aba32f41d1d146f34d55641dfa5586b90498fe55750d53ff - Sigstore transparency entry: 1731090664
- Sigstore integration time:
-
Permalink:
xxWeiDG/iris-next@4ffeaab881e68ac04d875acf0d54c8de3f812ada -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/xxWeiDG
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4ffeaab881e68ac04d875acf0d54c8de3f812ada -
Trigger Event:
release
-
Statement type:
File details
Details for the file iris_next-0.0.4-py3-none-any.whl.
File metadata
- Download URL: iris_next-0.0.4-py3-none-any.whl
- Upload date:
- Size: 24.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6bac32c98bd6002c5a819709f43759b5cb17711f4af06999272ca671931f21c
|
|
| MD5 |
cbc64d372d09fcc03a5819feb075878a
|
|
| BLAKE2b-256 |
ff30914b6178f20801537a19f77b6a3e9ff6ef7767e15670fc7506487341639c
|
Provenance
The following attestation bundles were made for iris_next-0.0.4-py3-none-any.whl:
Publisher:
publish.yml on xxWeiDG/iris-next
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
iris_next-0.0.4-py3-none-any.whl -
Subject digest:
c6bac32c98bd6002c5a819709f43759b5cb17711f4af06999272ca671931f21c - Sigstore transparency entry: 1731090745
- Sigstore integration time:
-
Permalink:
xxWeiDG/iris-next@4ffeaab881e68ac04d875acf0d54c8de3f812ada -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/xxWeiDG
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@4ffeaab881e68ac04d875acf0d54c8de3f812ada -
Trigger Event:
release
-
Statement type: