aigility 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.
adk/__init__.py ADDED
@@ -0,0 +1,45 @@
1
+ """
2
+ AIGility ADK - Agent Development Kit
3
+
4
+ 基于 LangGraph/LangChain 的智能体开发框架,提供:
5
+ - chat: 基础对话能力
6
+ - chatflow: 对话流管理
7
+ - workflow: 工作流引擎
8
+ - knowledge: 知识库管理
9
+ - memory: 记忆管理
10
+ """
11
+
12
+ __version__ = "0.0.1"
13
+ __author__ = "AIGility Cloud Innovation"
14
+ __email__ = "contact@aigility.com"
15
+ __description__ = "Agent Development Kit - 智能体开发框架"
16
+
17
+ # 导入主客户端
18
+ from .client import ADKClient, create_client
19
+
20
+ # 导入各模块
21
+ from . import memory
22
+ from . import chat
23
+ from . import chatflow
24
+ from . import workflow
25
+ from . import knowledge
26
+
27
+ __all__ = [
28
+ # 主客户端
29
+ "ADKClient",
30
+ "create_client",
31
+
32
+ # 模块
33
+ "memory",
34
+ "chat",
35
+ "chatflow",
36
+ "workflow",
37
+ "knowledge",
38
+
39
+ # 元信息
40
+ "__version__",
41
+ "__author__",
42
+ "__email__",
43
+ "__description__",
44
+ ]
45
+
adk/chat/__init__.py ADDED
@@ -0,0 +1,13 @@
1
+ """
2
+ ADK Chat - 基础对话模块
3
+
4
+ 基于 LangChain 提供基础对话能力。
5
+ """
6
+
7
+ from .agent import ChatAgent, create_chat_agent
8
+
9
+ __all__ = [
10
+ "ChatAgent",
11
+ "create_chat_agent",
12
+ ]
13
+
adk/chat/agent.py ADDED
@@ -0,0 +1,60 @@
1
+ """
2
+ Chat Agent
3
+
4
+ 基于 LangChain 的对话智能体。
5
+ """
6
+
7
+ from typing import Optional, List, Dict, Any
8
+ from ..core.base import BaseAgent
9
+ from ..core.types import State, Message, AgentResponse
10
+ from ..core.config import AgentConfig
11
+
12
+
13
+ class ChatAgent(BaseAgent):
14
+ """对话智能体"""
15
+
16
+ def __init__(
17
+ self,
18
+ name: str,
19
+ config: Optional[AgentConfig] = None,
20
+ llm: Optional[Any] = None, # LangChain LLM
21
+ tools: Optional[List[Any]] = None, # LangChain Tools
22
+ memory: Optional[Any] = None, # LangChain Memory
23
+ ):
24
+ super().__init__(name, config)
25
+ self.config = config or AgentConfig(name=name, description="")
26
+ self.llm = llm
27
+ self.tools = tools or []
28
+ self.memory = memory
29
+
30
+ # TODO: 初始化 LangChain Agent
31
+ # 这里需要使用 LangChain 的 Agent 类
32
+ self._agent = None
33
+
34
+ async def invoke(self, state: State) -> AgentResponse:
35
+ """
36
+ 执行对话
37
+
38
+ Args:
39
+ state: 当前状态
40
+
41
+ Returns:
42
+ 智能体响应
43
+ """
44
+ # TODO: 实现 LangChain Agent 调用
45
+ # 这里需要调用 LangChain 的 Agent
46
+ raise NotImplementedError("ChatAgent.invoke not yet implemented")
47
+
48
+ def get_prompt(self) -> str:
49
+ """获取提示词"""
50
+ return self.config.prompt_template or ""
51
+
52
+
53
+ def create_chat_agent(
54
+ name: str,
55
+ config: Optional[AgentConfig] = None,
56
+ **kwargs
57
+ ) -> ChatAgent:
58
+ """创建对话智能体"""
59
+ return ChatAgent(name=name, config=config, **kwargs)
60
+
@@ -0,0 +1,13 @@
1
+ """
2
+ ADK ChatFlow - 对话流管理模块
3
+
4
+ 基于 LangGraph 提供对话流管理能力。
5
+ """
6
+
7
+ from .flow import ChatFlow, create_chatflow
8
+
9
+ __all__ = [
10
+ "ChatFlow",
11
+ "create_chatflow",
12
+ ]
13
+
adk/chatflow/flow.py ADDED
@@ -0,0 +1,63 @@
1
+ """
2
+ ChatFlow
3
+
4
+ 基于 LangGraph 的对话流管理。
5
+ """
6
+
7
+ from typing import Optional, Dict, Any, List
8
+ from ..core.types import State, Message
9
+ from ..core.config import AgentConfig
10
+
11
+
12
+ class ChatFlow:
13
+ """对话流"""
14
+
15
+ def __init__(
16
+ self,
17
+ name: str,
18
+ agents: Optional[Dict[str, Any]] = None, # LangGraph Agents
19
+ graph: Optional[Any] = None, # LangGraph StateGraph
20
+ ):
21
+ self.name = name
22
+ self.agents = agents or {}
23
+ self.graph = graph
24
+
25
+ # TODO: 初始化 LangGraph StateGraph
26
+ # 这里需要使用 LangGraph 的 StateGraph 类
27
+
28
+ async def invoke(self, state: State) -> State:
29
+ """
30
+ 执行对话流
31
+
32
+ Args:
33
+ state: 初始状态
34
+
35
+ Returns:
36
+ 最终状态
37
+ """
38
+ # TODO: 实现 LangGraph 调用
39
+ # 这里需要调用 LangGraph 的 graph.invoke
40
+ raise NotImplementedError("ChatFlow.invoke not yet implemented")
41
+
42
+ async def stream(self, state: State):
43
+ """
44
+ 流式执行对话流
45
+
46
+ Args:
47
+ state: 初始状态
48
+
49
+ Yields:
50
+ 状态更新
51
+ """
52
+ # TODO: 实现 LangGraph 流式调用
53
+ raise NotImplementedError("ChatFlow.stream not yet implemented")
54
+
55
+
56
+ def create_chatflow(
57
+ name: str,
58
+ agents: Optional[Dict[str, Any]] = None,
59
+ **kwargs
60
+ ) -> ChatFlow:
61
+ """创建对话流"""
62
+ return ChatFlow(name=name, agents=agents, **kwargs)
63
+
adk/client.py ADDED
@@ -0,0 +1,167 @@
1
+ """
2
+ ADK 主客户端
3
+
4
+ 提供统一的客户端接口,使用 Builder 模式。
5
+ """
6
+
7
+ from typing import Optional, Dict, Any
8
+ from .core.config import ADKConfig
9
+ from .memory import Memory
10
+ from .chat import ChatAgent
11
+ from .chatflow import ChatFlow
12
+ from .workflow import WorkflowEngine
13
+ from .knowledge import KnowledgeStore
14
+
15
+
16
+ class ADKClient:
17
+ """
18
+ ADK 主客户端
19
+
20
+ 提供统一的接口访问所有 ADK 功能模块。
21
+ """
22
+
23
+ def __init__(self, config: Optional[ADKConfig] = None):
24
+ """
25
+ 初始化 ADK 客户端
26
+
27
+ Args:
28
+ config: ADK 配置
29
+ """
30
+ self.config = config or ADKConfig()
31
+
32
+ # 初始化各模块
33
+ self._memory: Optional[Memory] = None
34
+ self._knowledge_store: Optional[KnowledgeStore] = None
35
+
36
+ @property
37
+ def memory(self) -> Memory:
38
+ """获取记忆模块"""
39
+ if self._memory is None and self.config.memory_enabled:
40
+ self._memory = Memory(
41
+ api_key=self.config.memory_api_key,
42
+ base_url=self.config.memory_base_url,
43
+ )
44
+ return self._memory
45
+
46
+ def create_chat_agent(
47
+ self,
48
+ name: str,
49
+ **kwargs
50
+ ) -> ChatAgent:
51
+ """创建对话智能体"""
52
+ from .chat import create_chat_agent
53
+ return create_chat_agent(name=name, **kwargs)
54
+
55
+ def create_chatflow(
56
+ self,
57
+ name: str,
58
+ **kwargs
59
+ ) -> ChatFlow:
60
+ """创建对话流"""
61
+ from .chatflow import create_chatflow
62
+ return create_chatflow(name=name, **kwargs)
63
+
64
+ def create_workflow(
65
+ self,
66
+ name: str,
67
+ **kwargs
68
+ ) -> WorkflowEngine:
69
+ """创建工作流"""
70
+ from .workflow import create_workflow_engine
71
+ return create_workflow_engine(name=name, **kwargs)
72
+
73
+ async def close(self):
74
+ """关闭客户端"""
75
+ if self._memory:
76
+ await self._memory.close()
77
+
78
+
79
+ class ADKClientBuilder:
80
+ """ADK 客户端构建器"""
81
+
82
+ def __init__(self):
83
+ self.config = ADKConfig()
84
+
85
+ def with_llm(
86
+ self,
87
+ provider: str = "openai",
88
+ model: str = "gpt-4",
89
+ api_key: Optional[str] = None,
90
+ base_url: Optional[str] = None,
91
+ **kwargs
92
+ ) -> "ADKClientBuilder":
93
+ """配置 LLM"""
94
+ self.config.llm_provider = provider
95
+ self.config.llm_model = model
96
+ self.config.llm_api_key = api_key
97
+ self.config.llm_base_url = base_url
98
+ return self
99
+
100
+ def with_memory(
101
+ self,
102
+ api_key: Optional[str] = None,
103
+ base_url: Optional[str] = None,
104
+ enabled: bool = True
105
+ ) -> "ADKClientBuilder":
106
+ """配置记忆"""
107
+ self.config.memory_enabled = enabled
108
+ self.config.memory_api_key = api_key
109
+ self.config.memory_base_url = base_url
110
+ return self
111
+
112
+ def with_knowledge(
113
+ self,
114
+ store_type: str = "vector",
115
+ enabled: bool = True
116
+ ) -> "ADKClientBuilder":
117
+ """配置知识库"""
118
+ self.config.knowledge_enabled = enabled
119
+ self.config.knowledge_store_type = store_type
120
+ return self
121
+
122
+ def with_http(
123
+ self,
124
+ timeout: float = 60.0,
125
+ max_retries: int = 3,
126
+ verify_ssl: bool = False
127
+ ) -> "ADKClientBuilder":
128
+ """配置 HTTP"""
129
+ self.config.http_timeout = timeout
130
+ self.config.http_max_retries = max_retries
131
+ self.config.http_verify_ssl = verify_ssl
132
+ return self
133
+
134
+ def with_debug(self, enabled: bool = True) -> "ADKClientBuilder":
135
+ """配置调试模式"""
136
+ self.config.debug = enabled
137
+ self.config.log_level = "DEBUG" if enabled else "INFO"
138
+ return self
139
+
140
+ def build(self) -> ADKClient:
141
+ """构建客户端"""
142
+ return ADKClient(config=self.config)
143
+
144
+
145
+ def create_client(**kwargs) -> ADKClient:
146
+ """
147
+ 创建 ADK 客户端(快捷方式)
148
+
149
+ Args:
150
+ **kwargs: 配置参数
151
+
152
+ Returns:
153
+ ADK 客户端实例
154
+ """
155
+ builder = ADKClientBuilder()
156
+
157
+ if "llm_provider" in kwargs:
158
+ builder.with_llm(**{k.replace("llm_", ""): v for k, v in kwargs.items() if k.startswith("llm_")})
159
+
160
+ if "memory_api_key" in kwargs:
161
+ builder.with_memory(**{k.replace("memory_", ""): v for k, v in kwargs.items() if k.startswith("memory_")})
162
+
163
+ if "knowledge_store_type" in kwargs:
164
+ builder.with_knowledge(**{k.replace("knowledge_", ""): v for k, v in kwargs.items() if k.startswith("knowledge_")})
165
+
166
+ return builder.build()
167
+
adk/core/__init__.py ADDED
@@ -0,0 +1,22 @@
1
+ """
2
+ ADK Core - 核心功能模块
3
+
4
+ 提供基础抽象类、接口定义和通用工具。
5
+ """
6
+
7
+ from .base import BaseAgent, BaseTool, BaseMemory
8
+ from .config import ADKConfig, AgentConfig, ToolConfig
9
+ from .types import State, Message, AgentResponse
10
+
11
+ __all__ = [
12
+ "BaseAgent",
13
+ "BaseTool",
14
+ "BaseMemory",
15
+ "ADKConfig",
16
+ "AgentConfig",
17
+ "ToolConfig",
18
+ "State",
19
+ "Message",
20
+ "AgentResponse",
21
+ ]
22
+
adk/core/base.py ADDED
@@ -0,0 +1,85 @@
1
+ """
2
+ ADK 基础抽象类
3
+
4
+ 定义智能体、工具、记忆等核心组件的抽象接口。
5
+ """
6
+
7
+ from abc import ABC, abstractmethod
8
+ from typing import Any, Dict, List, Optional
9
+ from .types import State, Message, AgentResponse
10
+
11
+
12
+ class BaseAgent(ABC):
13
+ """智能体基类"""
14
+
15
+ def __init__(self, name: str, config: Optional[Dict[str, Any]] = None):
16
+ self.name = name
17
+ self.config = config or {}
18
+
19
+ @abstractmethod
20
+ async def invoke(self, state: State) -> AgentResponse:
21
+ """
22
+ 执行智能体逻辑
23
+
24
+ Args:
25
+ state: 当前状态
26
+
27
+ Returns:
28
+ 智能体响应
29
+ """
30
+ pass
31
+
32
+ @abstractmethod
33
+ def get_prompt(self) -> str:
34
+ """获取智能体的提示词"""
35
+ pass
36
+
37
+
38
+ class BaseTool(ABC):
39
+ """工具基类"""
40
+
41
+ def __init__(self, name: str, description: str, config: Optional[Dict[str, Any]] = None):
42
+ self.name = name
43
+ self.description = description
44
+ self.config = config or {}
45
+
46
+ @abstractmethod
47
+ async def invoke(self, **kwargs) -> Any:
48
+ """
49
+ 执行工具逻辑
50
+
51
+ Args:
52
+ **kwargs: 工具参数
53
+
54
+ Returns:
55
+ 工具执行结果
56
+ """
57
+ pass
58
+
59
+ @abstractmethod
60
+ def get_schema(self) -> Dict[str, Any]:
61
+ """获取工具的 JSON Schema"""
62
+ pass
63
+
64
+
65
+ class BaseMemory(ABC):
66
+ """记忆基类"""
67
+
68
+ def __init__(self, config: Optional[Dict[str, Any]] = None):
69
+ self.config = config or {}
70
+
71
+ @abstractmethod
72
+ async def add(self, messages: List[Message], **kwargs) -> Dict[str, Any]:
73
+ """添加记忆"""
74
+ pass
75
+
76
+ @abstractmethod
77
+ async def search(self, query: str, **kwargs) -> List[Dict[str, Any]]:
78
+ """搜索记忆"""
79
+ pass
80
+
81
+ @abstractmethod
82
+ async def get(self, memory_id: str) -> Dict[str, Any]:
83
+ """获取记忆"""
84
+ pass
85
+
adk/core/config.py ADDED
@@ -0,0 +1,76 @@
1
+ """
2
+ ADK 配置管理
3
+
4
+ 提供全局配置、智能体配置、工具配置等。
5
+ """
6
+
7
+ from typing import Any, Dict, List, Optional
8
+ from dataclasses import dataclass, field
9
+ from pydantic import BaseModel, Field
10
+
11
+
12
+ @dataclass
13
+ class ADKConfig:
14
+ """ADK 全局配置"""
15
+ # LLM 配置
16
+ llm_provider: str = "openai" # openai, anthropic, etc.
17
+ llm_model: str = "gpt-4"
18
+ llm_api_key: Optional[str] = None
19
+ llm_base_url: Optional[str] = None
20
+ llm_temperature: float = 0.7
21
+ llm_max_tokens: int = 2000
22
+
23
+ # Memory 配置
24
+ memory_enabled: bool = True
25
+ memory_api_key: Optional[str] = None
26
+ memory_base_url: Optional[str] = None
27
+
28
+ # Knowledge 配置
29
+ knowledge_enabled: bool = True
30
+ knowledge_store_type: str = "vector" # vector, graph, hybrid
31
+
32
+ # 工作流配置
33
+ workflow_timeout: float = 300.0
34
+ workflow_max_steps: int = 50
35
+
36
+ # HTTP 配置
37
+ http_timeout: float = 60.0
38
+ http_max_retries: int = 3
39
+ http_verify_ssl: bool = False
40
+
41
+ # 其他配置
42
+ debug: bool = False
43
+ log_level: str = "INFO"
44
+
45
+ def to_dict(self) -> Dict[str, Any]:
46
+ """转换为字典"""
47
+ return {
48
+ k: v for k, v in self.__dict__.items()
49
+ if not k.startswith("_")
50
+ }
51
+
52
+
53
+ @dataclass
54
+ class AgentConfig:
55
+ """智能体配置"""
56
+ name: str
57
+ description: str
58
+ prompt_template: Optional[str] = None
59
+ tools: List[str] = field(default_factory=list)
60
+ memory_enabled: bool = True
61
+ temperature: Optional[float] = None
62
+ max_tokens: Optional[int] = None
63
+ metadata: Dict[str, Any] = field(default_factory=dict)
64
+
65
+
66
+ @dataclass
67
+ class ToolConfig:
68
+ """工具配置"""
69
+ name: str
70
+ description: str
71
+ schema: Dict[str, Any]
72
+ enabled: bool = True
73
+ timeout: float = 30.0
74
+ max_retries: int = 3
75
+ metadata: Dict[str, Any] = field(default_factory=dict)
76
+
adk/core/types.py ADDED
@@ -0,0 +1,90 @@
1
+ """
2
+ ADK 类型定义
3
+
4
+ 定义状态、消息、响应等核心数据类型。
5
+ """
6
+
7
+ from typing import Any, Dict, List, Optional, Union
8
+ from dataclasses import dataclass, field
9
+ from datetime import datetime
10
+ from enum import Enum
11
+
12
+
13
+ class MessageRole(str, Enum):
14
+ """消息角色"""
15
+ USER = "user"
16
+ ASSISTANT = "assistant"
17
+ SYSTEM = "system"
18
+ TOOL = "tool"
19
+
20
+
21
+ @dataclass
22
+ class Message:
23
+ """消息对象"""
24
+ role: MessageRole
25
+ content: str
26
+ name: Optional[str] = None
27
+ tool_calls: Optional[List[Dict[str, Any]]] = None
28
+ tool_call_id: Optional[str] = None
29
+ metadata: Dict[str, Any] = field(default_factory=dict)
30
+ timestamp: datetime = field(default_factory=datetime.now)
31
+
32
+ def to_dict(self) -> Dict[str, Any]:
33
+ """转换为字典"""
34
+ return {
35
+ "role": self.role.value,
36
+ "content": self.content,
37
+ "name": self.name,
38
+ "tool_calls": self.tool_calls,
39
+ "tool_call_id": self.tool_call_id,
40
+ "metadata": self.metadata,
41
+ "timestamp": self.timestamp.isoformat(),
42
+ }
43
+
44
+ @classmethod
45
+ def from_dict(cls, data: Dict[str, Any]) -> "Message":
46
+ """从字典创建"""
47
+ return cls(
48
+ role=MessageRole(data["role"]),
49
+ content=data["content"],
50
+ name=data.get("name"),
51
+ tool_calls=data.get("tool_calls"),
52
+ tool_call_id=data.get("tool_call_id"),
53
+ metadata=data.get("metadata", {}),
54
+ timestamp=datetime.fromisoformat(data.get("timestamp", datetime.now().isoformat())),
55
+ )
56
+
57
+
58
+ @dataclass
59
+ class State:
60
+ """状态对象(用于工作流)"""
61
+ messages: List[Message] = field(default_factory=list)
62
+ context: Dict[str, Any] = field(default_factory=dict)
63
+ metadata: Dict[str, Any] = field(default_factory=dict)
64
+ next: Optional[str] = None
65
+
66
+ def update(self, **kwargs) -> "State":
67
+ """更新状态"""
68
+ for key, value in kwargs.items():
69
+ if hasattr(self, key):
70
+ setattr(self, key, value)
71
+ return self
72
+
73
+
74
+ @dataclass
75
+ class AgentResponse:
76
+ """智能体响应"""
77
+ content: str
78
+ tool_calls: Optional[List[Dict[str, Any]]] = None
79
+ metadata: Dict[str, Any] = field(default_factory=dict)
80
+ state: Optional[State] = None
81
+
82
+ def to_message(self, role: MessageRole = MessageRole.ASSISTANT) -> Message:
83
+ """转换为消息"""
84
+ return Message(
85
+ role=role,
86
+ content=self.content,
87
+ tool_calls=self.tool_calls,
88
+ metadata=self.metadata,
89
+ )
90
+
adk/http/__init__.py ADDED
@@ -0,0 +1,22 @@
1
+ """
2
+ ADK HTTP Transport Layer
3
+
4
+ 提供 HTTP 传输层,包括连接池、重试、熔断等功能。
5
+ """
6
+
7
+ from .client import HTTPClient, create_http_client
8
+ from .pool import ConnectionPool, ConnectionConfig
9
+ from .circuit_breaker import CircuitBreaker, CircuitBreakerConfig
10
+ from .retry import RetryConfig, RetryHandler
11
+
12
+ __all__ = [
13
+ "HTTPClient",
14
+ "create_http_client",
15
+ "ConnectionPool",
16
+ "ConnectionConfig",
17
+ "CircuitBreaker",
18
+ "CircuitBreakerConfig",
19
+ "RetryConfig",
20
+ "RetryHandler",
21
+ ]
22
+