zrb 1.15.6__py3-none-any.whl → 1.15.7__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.
- zrb/task/llm/print_node.py +72 -51
- zrb/task/llm/tool_wrapper.py +2 -2
- {zrb-1.15.6.dist-info → zrb-1.15.7.dist-info}/METADATA +1 -1
- {zrb-1.15.6.dist-info → zrb-1.15.7.dist-info}/RECORD +6 -6
- {zrb-1.15.6.dist-info → zrb-1.15.7.dist-info}/WHEEL +0 -0
- {zrb-1.15.6.dist-info → zrb-1.15.7.dist-info}/entry_points.txt +0 -0
zrb/task/llm/print_node.py
CHANGED
@@ -10,6 +10,7 @@ async def print_node(
|
|
10
10
|
):
|
11
11
|
"""Prints the details of an agent execution node using a provided print function."""
|
12
12
|
from pydantic_ai import Agent
|
13
|
+
from pydantic_ai.exceptions import UnexpectedModelBehavior
|
13
14
|
from pydantic_ai.messages import (
|
14
15
|
FinalResultEvent,
|
15
16
|
FunctionToolCallEvent,
|
@@ -21,70 +22,90 @@ async def print_node(
|
|
21
22
|
ToolCallPartDelta,
|
22
23
|
)
|
23
24
|
|
25
|
+
meta = getattr(node, "id", None) or getattr(node, "request_id", None)
|
24
26
|
if Agent.is_user_prompt_node(node):
|
25
27
|
print_func(_format_header("🔠 Receiving input...", log_indent_level))
|
26
28
|
elif Agent.is_model_request_node(node):
|
27
29
|
# A model request node => We can stream tokens from the model's request
|
28
30
|
print_func(_format_header("🧠 Processing...", log_indent_level))
|
29
31
|
# Reference: https://ai.pydantic.dev/agents/#streaming
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
if
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
event.delta,
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
32
|
+
try:
|
33
|
+
async with node.stream(agent_run.ctx) as request_stream:
|
34
|
+
is_streaming = False
|
35
|
+
async for event in request_stream:
|
36
|
+
if isinstance(event, PartStartEvent) and event.part:
|
37
|
+
if is_streaming:
|
38
|
+
print_func("")
|
39
|
+
content = _get_event_part_content(event)
|
40
|
+
print_func(_format_content(content, log_indent_level), end="")
|
41
|
+
is_streaming = True
|
42
|
+
elif isinstance(event, PartDeltaEvent):
|
43
|
+
if isinstance(event.delta, TextPartDelta) or isinstance(
|
44
|
+
event.delta, ThinkingPartDelta
|
45
|
+
):
|
46
|
+
content_delta = event.delta.content_delta
|
47
|
+
print_func(
|
48
|
+
_format_stream_content(content_delta, log_indent_level),
|
49
|
+
end="",
|
50
|
+
)
|
51
|
+
elif isinstance(event.delta, ToolCallPartDelta):
|
52
|
+
args_delta = event.delta.args_delta
|
53
|
+
print_func(
|
54
|
+
_format_stream_content(args_delta, log_indent_level),
|
55
|
+
end="",
|
56
|
+
)
|
57
|
+
is_streaming = True
|
58
|
+
elif isinstance(event, FinalResultEvent) and event.tool_name:
|
59
|
+
if is_streaming:
|
60
|
+
print_func("")
|
61
|
+
tool_name = event.tool_name
|
50
62
|
print_func(
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
elif isinstance(event, FinalResultEvent) and event.tool_name:
|
55
|
-
if is_streaming:
|
56
|
-
print_func("")
|
57
|
-
tool_name = event.tool_name
|
58
|
-
print_func(
|
59
|
-
_format_content(
|
60
|
-
f"Result: tool_name={tool_name}", log_indent_level
|
63
|
+
_format_content(
|
64
|
+
f"Result: tool_name={tool_name}", log_indent_level
|
65
|
+
)
|
61
66
|
)
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
67
|
+
is_streaming = False
|
68
|
+
if is_streaming:
|
69
|
+
print_func("")
|
70
|
+
except UnexpectedModelBehavior as e:
|
71
|
+
print_func("") # ensure newline consistency
|
72
|
+
print_func(
|
73
|
+
_format_content(
|
74
|
+
f"⚠️ Unexpected Model Behavior: {e}. node_id={meta}",
|
75
|
+
log_indent_level,
|
76
|
+
)
|
77
|
+
)
|
66
78
|
elif Agent.is_call_tools_node(node):
|
67
79
|
# A handle-response node => The model returned some data, potentially calls a tool
|
68
80
|
print_func(_format_header("🧰 Calling Tool...", log_indent_level))
|
69
|
-
|
70
|
-
async
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
81
|
+
try:
|
82
|
+
async with node.stream(agent_run.ctx) as handle_stream:
|
83
|
+
async for event in handle_stream:
|
84
|
+
if isinstance(event, FunctionToolCallEvent):
|
85
|
+
args = _get_event_part_args(event)
|
86
|
+
call_id = event.part.tool_call_id
|
87
|
+
tool_name = event.part.tool_name
|
88
|
+
print_func(
|
89
|
+
_format_content(
|
90
|
+
f"{call_id} | Call {tool_name} {args}", log_indent_level
|
91
|
+
)
|
78
92
|
)
|
79
|
-
)
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
93
|
+
elif isinstance(event, FunctionToolResultEvent):
|
94
|
+
call_id = event.tool_call_id
|
95
|
+
result_content = event.result.content
|
96
|
+
print_func(
|
97
|
+
_format_content(
|
98
|
+
f"{call_id} | {result_content}", log_indent_level
|
99
|
+
)
|
86
100
|
)
|
87
|
-
|
101
|
+
except UnexpectedModelBehavior as e:
|
102
|
+
print_func("") # ensure newline consistency
|
103
|
+
print_func(
|
104
|
+
_format_content(
|
105
|
+
f"⚠️ Unexpected Model Behavior: {e}. node_id={meta}",
|
106
|
+
log_indent_level,
|
107
|
+
)
|
108
|
+
)
|
88
109
|
elif Agent.is_end_node(node):
|
89
110
|
# Once an End node is reached, the agent run is complete
|
90
111
|
print_func(_format_header("✅ Completed...", log_indent_level))
|
zrb/task/llm/tool_wrapper.py
CHANGED
@@ -133,7 +133,7 @@ async def _ask_for_approval(
|
|
133
133
|
[
|
134
134
|
f"\n🎰 >> {func_call_str}",
|
135
135
|
_get_detail_func_param(args, kwargs),
|
136
|
-
f"
|
136
|
+
f"🎰 >> {_get_run_func_confirmation(func)}",
|
137
137
|
]
|
138
138
|
)
|
139
139
|
while True:
|
@@ -168,7 +168,7 @@ async def _ask_for_approval(
|
|
168
168
|
def _get_run_func_confirmation(func: Callable) -> str:
|
169
169
|
func_name = get_callable_name(func)
|
170
170
|
return render_markdown(
|
171
|
-
f"Allow to run `{func_name}`? (`Yes` | `No, <reason>`)"
|
171
|
+
f"Allow to run `{func_name}`? (✅ `Yes` | ⛔ `No, <reason>`)"
|
172
172
|
).strip()
|
173
173
|
|
174
174
|
|
@@ -355,9 +355,9 @@ zrb/task/llm/default_workflow/copywriting.md,sha256=xSO7GeDolwGxiuz6kXsK2GKGpwp8
|
|
355
355
|
zrb/task/llm/default_workflow/researching.md,sha256=KD-aYHFHir6Ti-4FsBBtGwiI0seSVgleYbKJZi_POXA,2139
|
356
356
|
zrb/task/llm/error.py,sha256=QR-nIohS6pBpC_16cWR-fw7Mevo1sNYAiXMBsh_CJDE,4157
|
357
357
|
zrb/task/llm/history_summarization.py,sha256=_eWFP4cAn3tTfyt7YPjnPwm_PgMhMChPg9g2q2Gsf0c,8172
|
358
|
-
zrb/task/llm/print_node.py,sha256=
|
358
|
+
zrb/task/llm/print_node.py,sha256=fNTL0LtoZBQQPHYCAUaOFP97nNNfobPXvY2RlxewQCE,7556
|
359
359
|
zrb/task/llm/prompt.py,sha256=FGXWYHecWtrNNkPnjg-uhnkqp7fYt8V91-AjFM_5fpA,11550
|
360
|
-
zrb/task/llm/tool_wrapper.py,sha256=
|
360
|
+
zrb/task/llm/tool_wrapper.py,sha256=SfDBDikT7cIqBThhLqrx4CFiNOmti8FAoBakRoEySqU,9619
|
361
361
|
zrb/task/llm/typing.py,sha256=c8VAuPBw_4A3DxfYdydkgedaP-LU61W9_wj3m3CAX1E,58
|
362
362
|
zrb/task/llm_task.py,sha256=0c9F_AjeMLxQX8VlAJHfZAkC52PhRaWbcKoqVOggcMg,14451
|
363
363
|
zrb/task/make_task.py,sha256=PD3b_aYazthS8LHeJsLAhwKDEgdurQZpymJDKeN60u0,2265
|
@@ -408,7 +408,7 @@ zrb/util/todo_model.py,sha256=hhzAX-uFl5rsg7iVX1ULlJOfBtblwQ_ieNUxBWfc-Os,1670
|
|
408
408
|
zrb/util/truncate.py,sha256=eSzmjBpc1Qod3lM3M73snNbDOcARHukW_tq36dWdPvc,921
|
409
409
|
zrb/xcom/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
410
410
|
zrb/xcom/xcom.py,sha256=o79rxR9wphnShrcIushA0Qt71d_p3ZTxjNf7x9hJB78,1571
|
411
|
-
zrb-1.15.
|
412
|
-
zrb-1.15.
|
413
|
-
zrb-1.15.
|
414
|
-
zrb-1.15.
|
411
|
+
zrb-1.15.7.dist-info/METADATA,sha256=N5AhEHwPxLzMKB9rL3NjqE4S-xyqWW4y3M-ATcz3CaQ,9774
|
412
|
+
zrb-1.15.7.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
413
|
+
zrb-1.15.7.dist-info/entry_points.txt,sha256=-Pg3ElWPfnaSM-XvXqCxEAa-wfVI6BEgcs386s8C8v8,46
|
414
|
+
zrb-1.15.7.dist-info/RECORD,,
|
File without changes
|
File without changes
|