-
Notifications
You must be signed in to change notification settings - Fork 2
Fix agui #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix agui #23
Changes from 3 commits
8e105ed
4939119
9aa51c8
b3ff8fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,8 @@ | |
| - Integration: 框架集成 / Framework integration | ||
| """ | ||
|
|
||
| from typing import TYPE_CHECKING | ||
|
|
||
| __version__ = "0.0.8" | ||
|
|
||
| # Agent Runtime | ||
|
|
@@ -87,27 +89,50 @@ | |
| SandboxClient, | ||
| Template, | ||
| ) | ||
| # Server | ||
| from agentrun.server import ( | ||
| AgentRequest, | ||
| AgentResult, | ||
| AgentRunServer, | ||
| AsyncInvokeAgentHandler, | ||
| InvokeAgentHandler, | ||
| Message, | ||
| MessageRole, | ||
| OpenAIProtocolHandler, | ||
| ProtocolHandler, | ||
| SyncInvokeAgentHandler, | ||
| ) | ||
| # ToolSet | ||
| from agentrun.toolset import ToolSet, ToolSetClient | ||
| from agentrun.utils.config import Config | ||
| from agentrun.utils.exception import ( | ||
| ResourceAlreadyExistError, | ||
| ResourceNotExistError, | ||
| ) | ||
| from agentrun.utils.model import Status | ||
|
|
||
| # Server - 延迟导入以避免可选依赖问题 | ||
| # Type hints for IDE and type checkers | ||
| if TYPE_CHECKING: | ||
| from agentrun.server import ( | ||
| AgentEvent, | ||
| AgentEventItem, | ||
| AgentRequest, | ||
| AgentResult, | ||
| AgentResultItem, | ||
| AgentReturnType, | ||
| AgentRunServer, | ||
| AguiEventNormalizer, | ||
| AGUIProtocolConfig, | ||
| AGUIProtocolHandler, | ||
| AsyncAgentEventGenerator, | ||
| AsyncAgentResultGenerator, | ||
| AsyncInvokeAgentHandler, | ||
| BaseProtocolHandler, | ||
| EventType, | ||
| InvokeAgentHandler, | ||
| MergeOptions, | ||
| Message, | ||
| MessageRole, | ||
| OpenAIProtocolConfig, | ||
| OpenAIProtocolHandler, | ||
| ProtocolConfig, | ||
| ProtocolHandler, | ||
| ServerConfig, | ||
| SyncAgentEventGenerator, | ||
| SyncAgentResultGenerator, | ||
| SyncInvokeAgentHandler, | ||
| Tool, | ||
| ToolCall, | ||
| ) | ||
|
|
||
| __all__ = [ | ||
| ######## Agent Runtime ######## | ||
| # base | ||
|
|
@@ -185,22 +210,106 @@ | |
| ######## ToolSet ######## | ||
| "ToolSetClient", | ||
| "ToolSet", | ||
| ######## Server ######## | ||
| ######## Server (延迟加载) ######## | ||
| # Server | ||
| "AgentRunServer", | ||
| # Config | ||
| "ServerConfig", | ||
| "ProtocolConfig", | ||
| "OpenAIProtocolConfig", | ||
| "AGUIProtocolConfig", | ||
| # Request/Response Models | ||
| "AgentRequest", | ||
| "AgentResponse", | ||
| "AgentEvent", | ||
| "AgentResult", | ||
| "AgentStreamResponse", | ||
| "Message", | ||
| "MessageRole", | ||
| "Tool", | ||
| "ToolCall", | ||
| # Event Types | ||
| "EventType", | ||
| # Type Aliases | ||
| "AgentEventItem", | ||
| "AgentResultItem", | ||
| "AgentReturnType", | ||
| "SyncAgentEventGenerator", | ||
| "SyncAgentResultGenerator", | ||
| "AsyncAgentEventGenerator", | ||
| "AsyncAgentResultGenerator", | ||
| "InvokeAgentHandler", | ||
| "AsyncInvokeAgentHandler", | ||
| "SyncInvokeAgentHandler", | ||
| "Message", | ||
| "MessageRole", | ||
| # Protocol Base | ||
| "ProtocolHandler", | ||
| "BaseProtocolHandler", | ||
| # Protocol - OpenAI | ||
| "OpenAIProtocolHandler", | ||
| "AgentStreamIterator", | ||
| # Protocol - AG-UI | ||
| "AGUIProtocolHandler", | ||
| # Event Normalizer | ||
| "AguiEventNormalizer", | ||
| # Helpers | ||
| "MergeOptions", | ||
| ######## Others ######## | ||
| "Status", | ||
| "ResourceNotExistError", | ||
| "ResourceAlreadyExistError", | ||
| "Config", | ||
| ] | ||
|
|
||
| # Server 模块的所有导出 | ||
| _SERVER_EXPORTS = { | ||
| "AgentRunServer", | ||
| "ServerConfig", | ||
| "ProtocolConfig", | ||
| "OpenAIProtocolConfig", | ||
| "AGUIProtocolConfig", | ||
| "AgentRequest", | ||
| "AgentEvent", | ||
| "AgentResult", | ||
| "Message", | ||
| "MessageRole", | ||
| "Tool", | ||
| "ToolCall", | ||
| "EventType", | ||
| "AgentEventItem", | ||
| "AgentResultItem", | ||
| "AgentReturnType", | ||
| "SyncAgentEventGenerator", | ||
| "SyncAgentResultGenerator", | ||
| "AsyncAgentEventGenerator", | ||
| "AsyncAgentResultGenerator", | ||
| "InvokeAgentHandler", | ||
| "AsyncInvokeAgentHandler", | ||
| "SyncInvokeAgentHandler", | ||
| "ProtocolHandler", | ||
| "BaseProtocolHandler", | ||
| "OpenAIProtocolHandler", | ||
| "AGUIProtocolHandler", | ||
| "AguiEventNormalizer", | ||
| "MergeOptions", | ||
| } | ||
|
|
||
|
|
||
| def __getattr__(name: str): | ||
| """延迟加载 server 模块的导出,避免可选依赖导致导入失败 | ||
|
|
||
| 当用户访问 server 相关的类时,才尝试导入 server 模块。 | ||
| 如果 server 可选依赖未安装,会抛出清晰的错误提示。 | ||
| """ | ||
| if name in _SERVER_EXPORTS: | ||
| try: | ||
| from agentrun import server | ||
|
|
||
| return getattr(server, name) | ||
| except ImportError as e: | ||
| # 检查是否是缺少可选依赖导致的错误 | ||
| if "fastapi" in str(e) or "uvicorn" in str(e): | ||
| raise ImportError( | ||
| f"'{name}' requires the 'server' optional dependencies. " | ||
| "Install with: pip install agentrun-sdk[server]\n" | ||
| f"Original error: {e}" | ||
| ) from e | ||
|
||
| # 其他导入错误继续抛出 | ||
| raise | ||
|
|
||
| raise AttributeError(f"module '{__name__}' has no attribute '{name}'") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Statusexport has been removed from__all__, but the import statementfrom agentrun.utils.model import Statusstill exists on line 99. This creates an inconsistency whereStatusis imported but not exported, making it unavailable to users who import from this module.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot open a new pull request to apply changes based on this feedback