zai-adk-python-preview 0.1.0__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.
- zai_adk/__init__.py +18 -0
- zai_adk/agent/__init__.py +26 -0
- zai_adk/agent/events.py +127 -0
- zai_adk/agent/service.py +1092 -0
- zai_adk/agent/types.py +66 -0
- zai_adk/context/__init__.py +13 -0
- zai_adk/context/compaction.py +312 -0
- zai_adk/context/models.py +127 -0
- zai_adk/llm/__init__.py +45 -0
- zai_adk/llm/anthropic/chat.py +344 -0
- zai_adk/llm/anthropic/serializer.py +490 -0
- zai_adk/llm/base.py +118 -0
- zai_adk/llm/exceptions.py +29 -0
- zai_adk/llm/messages.py +436 -0
- zai_adk/llm/openai/chat.py +386 -0
- zai_adk/llm/openai/serializer.py +315 -0
- zai_adk/llm/schema.py +293 -0
- zai_adk/llm/views.py +80 -0
- zai_adk/mcp/__init__.py +11 -0
- zai_adk/mcp/client.py +273 -0
- zai_adk/mcp/config.py +29 -0
- zai_adk/observability/__init__.py +7 -0
- zai_adk/observability/observability.py +281 -0
- zai_adk/protocols/__init__.py +49 -0
- zai_adk/protocols/agui/__init__.py +57 -0
- zai_adk/protocols/agui/converter.py +267 -0
- zai_adk/protocols/agui/encoder.py +51 -0
- zai_adk/protocols/agui/events.py +167 -0
- zai_adk/protocols/agui/protocol.py +93 -0
- zai_adk/protocols/base.py +71 -0
- zai_adk/sandbox/__init__.py +24 -0
- zai_adk/sandbox/base.py +178 -0
- zai_adk/sandbox/config.py +48 -0
- zai_adk/sandbox/factory.py +71 -0
- zai_adk/sandbox/local.py +260 -0
- zai_adk/skills/__init__.py +16 -0
- zai_adk/skills/manager.py +353 -0
- zai_adk/skills/parser.py +79 -0
- zai_adk/skills/types.py +49 -0
- zai_adk/skills/xml_generator.py +81 -0
- zai_adk/todo/__init__.py +5 -0
- zai_adk/todo/service.py +206 -0
- zai_adk/tokens/__init__.py +21 -0
- zai_adk/tokens/custom_pricing.py +11 -0
- zai_adk/tokens/mappings.py +6 -0
- zai_adk/tokens/service.py +420 -0
- zai_adk/tokens/views.py +112 -0
- zai_adk/tools/__init__.py +10 -0
- zai_adk/tools/builtin/__init__.py +38 -0
- zai_adk/tools/builtin/bash.py +36 -0
- zai_adk/tools/builtin/fs_edit.py +44 -0
- zai_adk/tools/builtin/fs_glob.py +32 -0
- zai_adk/tools/builtin/fs_grep.py +94 -0
- zai_adk/tools/builtin/fs_read.py +29 -0
- zai_adk/tools/builtin/fs_stat.py +33 -0
- zai_adk/tools/builtin/fs_write.py +31 -0
- zai_adk/tools/builtin/skill_exec.py +110 -0
- zai_adk/tools/builtin/skills.py +103 -0
- zai_adk/tools/builtin/task_run.py +129 -0
- zai_adk/tools/builtin/todo.py +107 -0
- zai_adk/tools/decorator.py +406 -0
- zai_adk/tools/depends.py +79 -0
- zai_adk_python_preview-0.1.0.dist-info/METADATA +369 -0
- zai_adk_python_preview-0.1.0.dist-info/RECORD +66 -0
- zai_adk_python_preview-0.1.0.dist-info/WHEEL +4 -0
- zai_adk_python_preview-0.1.0.dist-info/licenses/LICENSE +21 -0
zai_adk/__init__.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from zai_adk.agent import (
|
|
2
|
+
Agent,
|
|
3
|
+
AgentTemplate,
|
|
4
|
+
SubagentResult,
|
|
5
|
+
SubagentStatus,
|
|
6
|
+
)
|
|
7
|
+
from zai_adk.skills import SkillsManager, Skill, SkillMetadata, SkillContent
|
|
8
|
+
|
|
9
|
+
__all__ = [
|
|
10
|
+
"Agent",
|
|
11
|
+
"AgentTemplate",
|
|
12
|
+
"SubagentResult",
|
|
13
|
+
"SubagentStatus",
|
|
14
|
+
"SkillsManager",
|
|
15
|
+
"Skill",
|
|
16
|
+
"SkillMetadata",
|
|
17
|
+
"SkillContent",
|
|
18
|
+
]
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
from zai_adk.agent.events import (
|
|
2
|
+
AgentEvent,
|
|
3
|
+
FinalResponseEvent,
|
|
4
|
+
TextEvent,
|
|
5
|
+
ThinkingEvent,
|
|
6
|
+
ToolCallEvent,
|
|
7
|
+
ToolResultEvent,
|
|
8
|
+
)
|
|
9
|
+
from zai_adk.agent.service import Agent, TaskComplete
|
|
10
|
+
from zai_adk.agent.types import AgentTemplate, SubagentResult, SubagentStatus
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"Agent",
|
|
14
|
+
"TaskComplete",
|
|
15
|
+
# Events
|
|
16
|
+
"AgentEvent",
|
|
17
|
+
"FinalResponseEvent",
|
|
18
|
+
"TextEvent",
|
|
19
|
+
"ThinkingEvent",
|
|
20
|
+
"ToolCallEvent",
|
|
21
|
+
"ToolResultEvent",
|
|
22
|
+
# Subagent types
|
|
23
|
+
"AgentTemplate",
|
|
24
|
+
"SubagentResult",
|
|
25
|
+
"SubagentStatus",
|
|
26
|
+
]
|
zai_adk/agent/events.py
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Event types for agent streaming.
|
|
3
|
+
|
|
4
|
+
These events are yielded by `agent.query_stream()` to provide visibility
|
|
5
|
+
into the agent's execution.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
async for event in agent.query_stream("do something"):
|
|
9
|
+
match event:
|
|
10
|
+
case ToolCallEvent(tool=name, args=args):
|
|
11
|
+
print(f"Calling {name} with {args}")
|
|
12
|
+
case ToolResultEvent(tool=name, result=result):
|
|
13
|
+
print(f"{name} returned: {result}")
|
|
14
|
+
case TextEvent(content=text):
|
|
15
|
+
print(f"Assistant: {text}")
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
import json
|
|
19
|
+
from dataclasses import dataclass
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@dataclass
|
|
24
|
+
class TextEvent:
|
|
25
|
+
"""Emitted when the assistant produces text content."""
|
|
26
|
+
|
|
27
|
+
content: str
|
|
28
|
+
"""The text content from the assistant."""
|
|
29
|
+
|
|
30
|
+
def __str__(self) -> str:
|
|
31
|
+
preview = self.content[:100] + '...' if len(self.content) > 100 else self.content
|
|
32
|
+
return f'💬 {preview}'
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@dataclass
|
|
36
|
+
class ThinkingEvent:
|
|
37
|
+
"""Emitted when the model produces thinking/reasoning content."""
|
|
38
|
+
|
|
39
|
+
content: str
|
|
40
|
+
"""The thinking content."""
|
|
41
|
+
|
|
42
|
+
def __str__(self) -> str:
|
|
43
|
+
preview = self.content[:80] + '...' if len(self.content) > 80 else self.content
|
|
44
|
+
return f'🧠 {preview}'
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@dataclass
|
|
48
|
+
class ToolCallEvent:
|
|
49
|
+
"""Emitted when the assistant calls a tool."""
|
|
50
|
+
|
|
51
|
+
tool: str
|
|
52
|
+
"""The name of the tool being called."""
|
|
53
|
+
|
|
54
|
+
args: dict[str, Any]
|
|
55
|
+
"""The arguments passed to the tool."""
|
|
56
|
+
|
|
57
|
+
tool_call_id: str
|
|
58
|
+
"""The unique ID of this tool call."""
|
|
59
|
+
|
|
60
|
+
display_name: str = ''
|
|
61
|
+
"""Human-readable description of the tool call (e.g., 'Browsing https://...')."""
|
|
62
|
+
|
|
63
|
+
def __str__(self) -> str:
|
|
64
|
+
if self.display_name:
|
|
65
|
+
return f'🔧 {self.display_name}'
|
|
66
|
+
args_str = json.dumps(self.args, default=str)
|
|
67
|
+
if len(args_str) > 80:
|
|
68
|
+
args_str = args_str[:77] + '...'
|
|
69
|
+
return f'🔧 {self.tool}({args_str})'
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@dataclass
|
|
73
|
+
class ToolResultEvent:
|
|
74
|
+
"""Emitted when a tool returns a result."""
|
|
75
|
+
|
|
76
|
+
tool: str
|
|
77
|
+
"""The name of the tool that was called."""
|
|
78
|
+
|
|
79
|
+
result: str
|
|
80
|
+
"""The result returned by the tool."""
|
|
81
|
+
|
|
82
|
+
tool_call_id: str
|
|
83
|
+
"""The unique ID of the tool call this result corresponds to."""
|
|
84
|
+
|
|
85
|
+
is_error: bool = False
|
|
86
|
+
"""Whether the tool execution resulted in an error."""
|
|
87
|
+
|
|
88
|
+
def __str__(self) -> str:
|
|
89
|
+
prefix = '❌' if self.is_error else '✓'
|
|
90
|
+
preview = self.result[:80] + '...' if len(self.result) > 80 else self.result
|
|
91
|
+
return f' {prefix} {self.tool}: {preview}'
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
@dataclass
|
|
95
|
+
class FinalResponseEvent:
|
|
96
|
+
"""Emitted when the agent produces its final response."""
|
|
97
|
+
|
|
98
|
+
content: str
|
|
99
|
+
"""The final response content."""
|
|
100
|
+
|
|
101
|
+
def __str__(self) -> str:
|
|
102
|
+
return f'✅ Final: {self.content[:100]}...' if len(self.content) > 100 else f'✅ Final: {self.content}'
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@dataclass
|
|
106
|
+
class HiddenUserMessageEvent:
|
|
107
|
+
"""Emitted when the agent injects a hidden user message (ex: incomplete todos prompt).
|
|
108
|
+
Hidden messages are saved to history and sent to the LLM but not displayed in the UI.
|
|
109
|
+
"""
|
|
110
|
+
|
|
111
|
+
content: str
|
|
112
|
+
"""The content of the hidden user message."""
|
|
113
|
+
|
|
114
|
+
def __str__(self) -> str:
|
|
115
|
+
preview = self.content[:80] + '...' if len(self.content) > 80 else self.content
|
|
116
|
+
return f'👻 Hidden: {preview}'
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
# Union type for all events
|
|
120
|
+
AgentEvent = (
|
|
121
|
+
TextEvent
|
|
122
|
+
| ThinkingEvent
|
|
123
|
+
| ToolCallEvent
|
|
124
|
+
| ToolResultEvent
|
|
125
|
+
| FinalResponseEvent
|
|
126
|
+
| HiddenUserMessageEvent
|
|
127
|
+
)
|