fast-agents-py 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. fast_agents_py/__init__.py +97 -0
  2. fast_agents_py/agents/__init__.py +7 -0
  3. fast_agents_py/agents/agent_base.py +47 -0
  4. fast_agents_py/agents/react_agent/prompt.py +20 -0
  5. fast_agents_py/agents/react_agent/react_agent.py +905 -0
  6. fast_agents_py/context/__init__.py +51 -0
  7. fast_agents_py/context/builder.py +352 -0
  8. fast_agents_py/context/compressor.py +307 -0
  9. fast_agents_py/context/layers.py +207 -0
  10. fast_agents_py/context/offload.py +298 -0
  11. fast_agents_py/context/tokens.py +252 -0
  12. fast_agents_py/context/tools.py +171 -0
  13. fast_agents_py/database/__init__.py +92 -0
  14. fast_agents_py/database/chroma_client.py +624 -0
  15. fast_agents_py/database/database_client_base.py +546 -0
  16. fast_agents_py/database/errors.py +59 -0
  17. fast_agents_py/database/mysql_client.py +633 -0
  18. fast_agents_py/database/query.py +77 -0
  19. fast_agents_py/database/schema.py +214 -0
  20. fast_agents_py/database/sqlite_client.py +509 -0
  21. fast_agents_py/database/vector_client_base.py +164 -0
  22. fast_agents_py/database/vector_query.py +71 -0
  23. fast_agents_py/llm/__init__.py +61 -0
  24. fast_agents_py/llm/errors.py +134 -0
  25. fast_agents_py/llm/llm.py +420 -0
  26. fast_agents_py/llm/models.py +22 -0
  27. fast_agents_py/llm/openai_client.py +592 -0
  28. fast_agents_py/llm/retry.py +393 -0
  29. fast_agents_py/llm/retry_errors.py +21 -0
  30. fast_agents_py/mcp/__init__.py +47 -0
  31. fast_agents_py/mcp/client.py +389 -0
  32. fast_agents_py/mcp/errors.py +19 -0
  33. fast_agents_py/mcp/models.py +227 -0
  34. fast_agents_py/mcp/registry.py +355 -0
  35. fast_agents_py/mcp/tool.py +394 -0
  36. fast_agents_py/mcp/transports/__init__.py +25 -0
  37. fast_agents_py/mcp/transports/sse_transport.py +213 -0
  38. fast_agents_py/mcp/transports/stdio_transport.py +244 -0
  39. fast_agents_py/mcp/transports/streamable_http_transport.py +362 -0
  40. fast_agents_py/mcp/transports/transport_base.py +26 -0
  41. fast_agents_py/memory/__init__.py +29 -0
  42. fast_agents_py/memory/buffer.py +219 -0
  43. fast_agents_py/memory/chroma_store.py +768 -0
  44. fast_agents_py/memory/errors.py +31 -0
  45. fast_agents_py/memory/in_memory_store.py +60 -0
  46. fast_agents_py/memory/manager.py +645 -0
  47. fast_agents_py/memory/memory_store_base.py +339 -0
  48. fast_agents_py/memory/models.py +200 -0
  49. fast_agents_py/memory/profile_store.py +199 -0
  50. fast_agents_py/memory/scoring.py +204 -0
  51. fast_agents_py/memory/semantic_store.py +725 -0
  52. fast_agents_py/memory/session_store.py +362 -0
  53. fast_agents_py/memory/sqlite_store.py +373 -0
  54. fast_agents_py/messages/__init__.py +25 -0
  55. fast_agents_py/messages/message.py +147 -0
  56. fast_agents_py/messages/messages.py +71 -0
  57. fast_agents_py/messages/parts.py +132 -0
  58. fast_agents_py/skills/__init__.py +45 -0
  59. fast_agents_py/skills/base.py +192 -0
  60. fast_agents_py/skills/errors.py +119 -0
  61. fast_agents_py/skills/loader.py +1281 -0
  62. fast_agents_py/skills/middleware.py +546 -0
  63. fast_agents_py/skills/models.py +343 -0
  64. fast_agents_py/skills/registry.py +868 -0
  65. fast_agents_py/tools/__init__.py +28 -0
  66. fast_agents_py/tools/builtin/__init__.py +69 -0
  67. fast_agents_py/tools/builtin/calculator_tool.py +103 -0
  68. fast_agents_py/tools/builtin/command_splitter.py +189 -0
  69. fast_agents_py/tools/builtin/file_tool.py +837 -0
  70. fast_agents_py/tools/builtin/mcp_tool.py +176 -0
  71. fast_agents_py/tools/builtin/memory_tool.py +159 -0
  72. fast_agents_py/tools/builtin/search_tool.py +89 -0
  73. fast_agents_py/tools/builtin/shell_check.py +72 -0
  74. fast_agents_py/tools/builtin/shell_detector.py +299 -0
  75. fast_agents_py/tools/builtin/terminal_tool.py +288 -0
  76. fast_agents_py/tools/structured_tool.py +135 -0
  77. fast_agents_py/tools/tool_base.py +447 -0
  78. fast_agents_py/tools/tool_exception.py +21 -0
  79. fast_agents_py/tools/tool_registry.py +339 -0
  80. fast_agents_py/tools/tool_result.py +93 -0
  81. fast_agents_py/trace/__init__.py +54 -0
  82. fast_agents_py/trace/evaluator.py +1365 -0
  83. fast_agents_py/trace/in_memory_trace_store.py +50 -0
  84. fast_agents_py/trace/jsonl_store.py +137 -0
  85. fast_agents_py/trace/models.py +364 -0
  86. fast_agents_py/trace/schema.py +36 -0
  87. fast_agents_py/trace/sqlite_store.py +183 -0
  88. fast_agents_py/trace/store_base.py +58 -0
  89. fast_agents_py/trace/trace_logger.py +607 -0
  90. fast_agents_py/utils/__init__.py +0 -0
  91. fast_agents_py/utils/json_utils.py +90 -0
  92. fast_agents_py/utils/time_utils.py +44 -0
  93. fast_agents_py/utils/utils.py +10 -0
  94. fast_agents_py/version.py +6 -0
  95. fast_agents_py-0.0.1.dist-info/METADATA +1421 -0
  96. fast_agents_py-0.0.1.dist-info/RECORD +98 -0
  97. fast_agents_py-0.0.1.dist-info/WHEEL +4 -0
  98. fast_agents_py-0.0.1.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,97 @@
1
+ """FastAgents - 灵活、可扩展的多智能体框架"""
2
+
3
+ from dotenv import load_dotenv
4
+ load_dotenv()
5
+
6
+ from .version import __version__, __author__, __email__, __description__
7
+ from .llm import LLM
8
+ from .messages import (
9
+ Message, Messages, Content, ContentPart,
10
+ TextPart, ImagePart, content_to_text, normalize_content, PartType,
11
+ )
12
+ from .agents.react_agent.react_agent import ReActAgent
13
+ from .tools import (
14
+ ToolBase, StructuredTool, tool, ToolResult, ToolStatus,
15
+ ToolException, ToolRegistry, global_registry, builtin,
16
+ )
17
+ from .memory import MemoryManager
18
+ from .context import (
19
+ ContextBuilder, BuildReport,
20
+ TokenCounter, TokenBudget, estimate_text_tokens,
21
+ ContextWindow, ContextLayer,
22
+ ContextCompressor, ContextOffloader,
23
+ ReadOffloadedTool, ListFilesTool,
24
+ build_context_tools,
25
+ )
26
+ from .mcp import (
27
+ MCPRegistry, MCPClient, MCPToolAdapter, MCPServerTool,
28
+ MCPError, MCPConnectionError, MCPProtocolError, MCPCallError,
29
+ StdioTransport, SSETransport, StreamableHTTPTransport,
30
+ make_stdio_transport, make_streamable_http_transport,
31
+ MCPConfig,
32
+ )
33
+ from .database import (
34
+ SQLiteClient, MySQLClient, DatabaseClientBase,
35
+ Schema, Column, ColumnType, Index,
36
+ Query, Filter, FilterOp, SortOrder,
37
+ DatabaseError, DatabaseConnectionError,
38
+ DatabaseOperationalError, DatabaseValidationError,
39
+ )
40
+ from .trace import (
41
+ TraceLogger, SpanKind, SpanStatus, SpanRecord,
42
+ TraceStoreBase, JsonlStore, MEMORY_PATH, SQLiteStore,
43
+ )
44
+ from .skills import (
45
+ BaseSkill, skill,
46
+ SkillRegistry, SkillLoader, SkillMiddleware,
47
+ SkillMetadata, SkillLoadResult,
48
+ )
49
+
50
+ __all__ = [
51
+ # 版本信息
52
+ "__version__", "__author__", "__email__", "__description__",
53
+
54
+ # Agent范式
55
+ "LLM", "ReActAgent",
56
+
57
+ # 消息系统(多模态支持)
58
+ "Message", "Messages",
59
+ "Content", "ContentPart", "TextPart", "ImagePart",
60
+ "content_to_text", "normalize_content", "PartType",
61
+
62
+ # 工具系统
63
+ "ToolBase", "StructuredTool", "tool", "ToolResult", "ToolStatus",
64
+ "ToolException", "ToolRegistry", "global_registry", "builtin",
65
+
66
+ # 记忆系统
67
+ "MemoryManager",
68
+
69
+ # 上下文工程
70
+ "ContextBuilder", "BuildReport",
71
+ "TokenCounter", "TokenBudget", "estimate_text_tokens",
72
+ "ContextWindow", "ContextLayer",
73
+ "ContextCompressor", "ContextOffloader",
74
+ "ReadOffloadedTool", "ListFilesTool",
75
+ "build_context_tools",
76
+
77
+ # MCP
78
+ "MCPRegistry", "MCPClient", "MCPToolAdapter", "MCPServerTool",
79
+ "MCPError", "MCPConnectionError", "MCPProtocolError", "MCPCallError",
80
+ "StdioTransport", "SSETransport", "make_stdio_transport", "MCPConfig",
81
+
82
+ # Database(持久化层)
83
+ "SQLiteClient", "MySQLClient", "DatabaseClientBase",
84
+ "Schema", "Column", "ColumnType", "Index",
85
+ "Query", "Filter", "FilterOp", "SortOrder",
86
+ "DatabaseError", "DatabaseConnectionError",
87
+ "DatabaseOperationalError", "DatabaseValidationError",
88
+
89
+ # Trace(可观测性,G1 初版,v1.1.0 新增 SQLiteStore)
90
+ "TraceLogger", "SpanKind", "SpanStatus", "SpanRecord",
91
+ "TraceStoreBase", "JsonlStore", "MEMORY_PATH", "SQLiteStore",
92
+
93
+ # Skills 技能系统(v1.1.0)
94
+ "BaseSkill", "skill",
95
+ "SkillRegistry", "SkillLoader", "SkillMiddleware",
96
+ "SkillMetadata", "SkillLoadResult",
97
+ ]
@@ -0,0 +1,7 @@
1
+ """Agent模块"""
2
+
3
+ from .agent_base import AgentBase
4
+
5
+ __all__ = [
6
+ "AgentBase",
7
+ ]
@@ -0,0 +1,47 @@
1
+ """Agent基类"""
2
+
3
+ from abc import ABC, abstractmethod
4
+ from typing import Iterator, Optional
5
+
6
+ from ..messages import Messages
7
+ from ..messages.message import Message
8
+ from ..llm import LLM
9
+ from ..llm.models import StreamChunk
10
+
11
+
12
+ class AgentBase(ABC):
13
+ """Agent基类"""
14
+
15
+ def __init__(self, name: str, llm: LLM, system_prompt: Optional[str] = None):
16
+ self.name = name
17
+ self.llm : LLM = llm
18
+ self.system_prompt = system_prompt
19
+ self.messages_simple: Messages = Messages()
20
+
21
+ @abstractmethod
22
+ def run(self, input_text: str, **kwargs) -> str:
23
+ """运行Agent,返回最终答案字符串"""
24
+ pass
25
+
26
+ @abstractmethod
27
+ def run_stream(self, input_text: str, **kwargs) -> Iterator[StreamChunk]:
28
+ """流式运行Agent,按StreamChunk契约产出事件,支持打字机效果"""
29
+ pass
30
+
31
+ def add_message(self, message: Message):
32
+ """添加消息到历史记录"""
33
+ self.messages_simple.append(message)
34
+
35
+ def clear_history(self):
36
+ """清空历史记录"""
37
+ self.messages_simple.clear()
38
+
39
+ def get_history(self) -> list[Message]:
40
+ """获取历史记录"""
41
+ return self.messages_simple.get_messages()
42
+
43
+ def __str__(self) -> str:
44
+ return f"Agent(name={self.name}, provider={self.llm.provider})"
45
+
46
+ def __repr__(self) -> str:
47
+ return self.__str__()
@@ -0,0 +1,20 @@
1
+ # 默认ReAct提示词模板
2
+ DEFAULT_REACT_PROMPT = """你是一个具备推理和行动能力的AI助手。
3
+ 你可以通过思考分析问题,然后调用合适的工具来获取信息,最终给出准确的答案。
4
+
5
+ ## 可用工具
6
+ {tools}
7
+
8
+ ## 重要规则
9
+ 1. 你的所有内部思考过程、规划步骤必须使用中文。
10
+ 2. 你的最终回答也必须使用中文。
11
+ 3. 不要使用英文进行思考或回答。
12
+ 4. 回答尽可能简单
13
+
14
+ ## 技能使用规范
15
+ 1. 先索引后加载:看到匹配的技能时,先调用 load_skill 加载完整指令,不要猜测技能的执行流程。
16
+ 2. 严格遵循指令:加载技能后,按其中的步骤和规范执行,不要跳步或省略。
17
+ 3. 按需读取:需要参考文档时用 read_skill_reference,需要执行脚本时用 run_skill_script。
18
+ 4. 简单问题、通用知识问答无需加载技能。
19
+
20
+ 现在开始你的推理和行动:"""