FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sdk-python/tests_integ/test_stream_agent.py at main · polytech-dev/sdk-python · GitHub
polytech-dev
/
sdk-python
Public
forked from
strands-agents/harness-sdk
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sdk-python
/
tests_integ
/
test_stream_agent.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
70 lines (54 loc) · 2.21 KB
Breadcrumbs
sdk-python
/
tests_integ
/
test_stream_agent.py
Copy path
File metadata and controls
70 lines (54 loc) · 2.21 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
Test script for Strands' custom callback handler functionality.
Demonstrates different patterns of callback handling and processing.
"""
import
logging
from
strands
import
Agent
logging
.
getLogger
(
"strands"
).
setLevel
(
logging
.
DEBUG
)
logging
.
basicConfig
(
format
=
"%(levelname)s | %(name)s | %(message)s"
,
handlers
=
[
logging
.
StreamHandler
()])
class
ToolCountingCallbackHandler
:
def
__init__
(
self
):
self
.
tool_count
=
0
self
.
message_count
=
0
def
callback_handler
(
self
,
**
kwargs
)
->
None
:
"""
Custom callback handler that processes and displays different types of events.
Args:
**kwargs: Callback event data including:
- data: Regular output
- complete: Completion status
- message: Message processing
- current_tool_use: Tool execution
"""
# Extract event data
data
=
kwargs
.
get
(
"data"
,
""
)
complete
=
kwargs
.
get
(
"complete"
,
False
)
message
=
kwargs
.
get
(
"message"
, {})
current_tool_use
=
kwargs
.
get
(
"current_tool_use"
, {})
# Handle regular data output
if
data
:
print
(
f"🔄 Data:
{
data
}
"
)
# Handle tool execution events
if
current_tool_use
:
self
.
tool_count
+=
1
tool_name
=
current_tool_use
.
get
(
"name"
,
""
)
tool_input
=
current_tool_use
.
get
(
"input"
, {})
print
(
f"🛠️ Tool Execution #
{
self
.
tool_count
}
\n
Tool:
{
tool_name
}
\n
Input:
{
tool_input
}
"
)
# Handle message processing
if
message
:
self
.
message_count
+=
1
print
(
f"📝 Message #
{
self
.
message_count
}
"
)
# Handle completion
if
complete
:
self
.
console
.
print
(
"✨ Callback Complete"
,
style
=
"bold green"
)
def
test_basic_interaction
():
"""Test basic AGI interaction with custom callback handler."""
print
(
"
\n
Testing Basic Interaction"
)
# Initialize agent with custom handler
agent
=
Agent
(
callback_handler
=
ToolCountingCallbackHandler
().
callback_handler
,
load_tools_from_directory
=
False
,
)
# Simple prompt to test callbacking
agent
(
"Tell me a short joke from your general knowledge"
)
print
(
"
\n
Basic Interaction Complete"
)
Back
|
FazBrowse Home
|
New Git URL