Skip to content

Commit c97fd2f

Browse files
committed
agentic notebook support
1 parent 66d8c4e commit c97fd2f

File tree

14 files changed

+1575
-930
lines changed

14 files changed

+1575
-930
lines changed

examples/tutorials/00_sync/020_streaming/dev.ipynb

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 9,
5+
"execution_count": 1,
66
"id": "36834357",
77
"metadata": {},
88
"outputs": [],
@@ -14,7 +14,7 @@
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": 10,
17+
"execution_count": 2,
1818
"id": "d1c309d6",
1919
"metadata": {},
2020
"outputs": [],
@@ -24,7 +24,7 @@
2424
},
2525
{
2626
"cell_type": "code",
27-
"execution_count": 11,
27+
"execution_count": 3,
2828
"id": "9f6e6ef0",
2929
"metadata": {},
3030
"outputs": [],
@@ -50,24 +50,33 @@
5050
},
5151
{
5252
"cell_type": "code",
53-
"execution_count": 12,
53+
"execution_count": 9,
5454
"id": "b03b0d37",
5555
"metadata": {},
5656
"outputs": [
5757
{
5858
"name": "stdout",
5959
"output_type": "stream",
6060
"text": [
61+
"AGENT [07/27/2025 00:52:20]\n",
6162
"Hello! I can assist you with a variety of tasks, including:\n",
6263
"\n",
63-
"1. Answering questions across a wide range of topics, such as science, history, technology, and more.\n",
64-
"2. Providing explanations and summaries of complex concepts.\n",
65-
"3. Offering writing assistance, including grammar and style suggestions.\n",
66-
"4. Helping with language translation and learning.\n",
67-
"5. Providing recommendations for books, movies, or other media.\n",
68-
"6. Engaging in general conversation or brainstorming ideas.\n",
64+
"1. **Answering Questions**: I can provide information on a wide range of topics, including science, history, technology, and more.\n",
65+
"\n",
66+
"2. **Providing Explanations**: If you need clarification on a concept or topic, I can help explain it in simpler terms.\n",
67+
"\n",
68+
"3. **Offering Writing Assistance**: I can help you with writing tasks, such as drafting emails, essays, or creative writing, and provide editing suggestions.\n",
6969
"\n",
70-
"Feel free to ask me anything specific you'd like help with!\n"
70+
"4. **Language Help**: I can assist with language learning, including vocabulary, grammar, and translations in multiple languages.\n",
71+
"\n",
72+
"5. **Research Support**: I can help you find facts or summarize information on specific subjects.\n",
73+
"\n",
74+
"6. **General Advice**: I can provide tips or suggestions on various life topics, such as study techniques, productivity, or personal development.\n",
75+
"\n",
76+
"7. **Fun and Games**: If you’re looking for entertainment, I can generate quizzes, riddles, or engage in light-hearted conversation.\n",
77+
"\n",
78+
"Feel free to ask me anything specific you have in mind!\n",
79+
"\n"
7180
]
7281
}
7382
],
@@ -111,7 +120,7 @@
111120
},
112121
{
113122
"cell_type": "code",
114-
"execution_count": 13,
123+
"execution_count": 10,
115124
"id": "79688331",
116125
"metadata": {},
117126
"outputs": [
@@ -121,15 +130,15 @@
121130
"text": [
122131
"Hello! I can assist you with a variety of tasks, including:\n",
123132
"\n",
124-
"1. **Answering Questions**: I can provide information and answer questions on a wide range of topics, from general knowledge to specific subjects.\n",
125-
"2. **Providing Explanations**: If you need clarification on concepts or topics, I can explain them in detail.\n",
126-
"3. **Assisting with Writing**: I can help you draft emails, essays, reports, and other written documents.\n",
127-
"4. **Generating Ideas**: If you're looking for creative ideas or brainstorming, I can help with that too.\n",
128-
"5. **Learning and Study Help**: I can provide educational support, including summaries, study techniques, and practice questions.\n",
129-
"6. **Language Assistance**: If you need help with language learning or translation, I can assist with that as well.\n",
130-
"7. **Problem-Solving**: I can help you think through problems or challenges you might be facing.\n",
133+
"1. Answering questions and providing information on a wide range of topics.\n",
134+
"2. Offering explanations or summaries of concepts.\n",
135+
"3. Helping with writing, including essays, reports, and creative writing.\n",
136+
"4. Assisting with problem-solving in subjects like math and science.\n",
137+
"5. Providing language translation or helping with language learning.\n",
138+
"6. Offering recommendations for books, movies, or other media.\n",
139+
"7. Engaging in conversation and discussion on various topics.\n",
131140
"\n",
132-
"Feel free to ask me anything, and I'll do my best to help you!"
141+
"If you have something specific you need help with, just let me know!"
133142
]
134143
}
135144
],
Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 6,
6+
"id": "36834357",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"from agentex import Agentex\n",
11+
"\n",
12+
"client = Agentex(base_url=\"http://localhost:5003\")"
13+
]
14+
},
15+
{
16+
"cell_type": "code",
17+
"execution_count": 7,
18+
"id": "d1c309d6",
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"AGENT_NAME = \"ab020-streaming\""
23+
]
24+
},
25+
{
26+
"cell_type": "code",
27+
"execution_count": 8,
28+
"id": "9f6e6ef0",
29+
"metadata": {},
30+
"outputs": [
31+
{
32+
"name": "stdout",
33+
"output_type": "stream",
34+
"text": [
35+
"Task(id='fab911e3-47c5-43f2-9942-382a98d45975', created_at=datetime.datetime(2025, 7, 27, 0, 52, 55, 493055, tzinfo=TzInfo(UTC)), name='69297be2-task', status='RUNNING', status_reason='Task created, forwarding to ACP server', updated_at=datetime.datetime(2025, 7, 27, 0, 52, 55, 493055, tzinfo=TzInfo(UTC)))\n"
36+
]
37+
}
38+
],
39+
"source": [
40+
"# (REQUIRED) Create a new task. For Agentic agents, you must create a task for messages to be associated with.\n",
41+
"\n",
42+
"from typing import cast\n",
43+
"import uuid\n",
44+
"\n",
45+
"from agentex.types import Task\n",
46+
"\n",
47+
"TASK_ID = str(uuid.uuid4())[:8]\n",
48+
"\n",
49+
"rpc_response = client.agents.rpc_by_name(\n",
50+
" agent_name=AGENT_NAME,\n",
51+
" method=\"task/create\",\n",
52+
" params={\n",
53+
" \"name\": f\"{TASK_ID}-task\",\n",
54+
" \"params\": {}\n",
55+
" }\n",
56+
")\n",
57+
"\n",
58+
"task = cast(Task, rpc_response.result)\n",
59+
"print(task)"
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": null,
65+
"id": "b03b0d37",
66+
"metadata": {},
67+
"outputs": [
68+
{
69+
"name": "stdout",
70+
"output_type": "stream",
71+
"text": [
72+
"Event(id='6f1c066c-f400-49a5-a8bd-afe0f2367b4c', agent_id='ef21f2e7-5bbe-440a-824b-7e89f462a781', sequence_id=203, task_id='fab911e3-47c5-43f2-9942-382a98d45975', content=TextContent(author='user', content='Hello what can you do?', attachments=None, format='plain', style='static', type='text'), created_at=datetime.datetime(2025, 7, 27, 0, 52, 56, 693376, tzinfo=TzInfo(UTC)))\n"
73+
]
74+
}
75+
],
76+
"source": [
77+
"# Test non streaming response\n",
78+
"from typing import cast\n",
79+
"from agentex.types import Event\n",
80+
"\n",
81+
"# The response is expected to be a list of TaskMessage objects, which is a union of the following types:\n",
82+
"# - TextContent: A message with just text content \n",
83+
"# - DataContent: A message with JSON-serializable data content\n",
84+
"# - ToolRequestContent: A message with a tool request, which contains a JSON-serializable request to call a tool\n",
85+
"# - ToolResponseContent: A message with a tool response, which contains response object from a tool call in its content\n",
86+
"\n",
87+
"# When processing the message/send response, if you are expecting more than TextContent, such as DataContent, ToolRequestContent, or ToolResponseContent, you can process them as well\n",
88+
"\n",
89+
"rpc_response = client.agents.rpc_by_name(\n",
90+
" agent_name=AGENT_NAME,\n",
91+
" method=\"event/send\",\n",
92+
" params={\n",
93+
" \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello what can you do?\"},\n",
94+
" \"task_id\": task.id,\n",
95+
" }\n",
96+
")\n",
97+
"\n",
98+
"event = cast(Event, rpc_response.result)\n",
99+
"print(event)"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": 10,
105+
"id": "a6927cc0",
106+
"metadata": {},
107+
"outputs": [
108+
{
109+
"data": {
110+
"text/html": [
111+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #00ffff; text-decoration-color: #00ffff\">╭───────────────────────── </span><span style=\"color: #00ffff; text-decoration-color: #00ffff; font-weight: bold\">USER</span><span style=\"color: #00ffff; text-decoration-color: #00ffff\"> [07/27/2025 00:52:56] ─────────────────────────╮</span>\n",
112+
"<span style=\"color: #00ffff; text-decoration-color: #00ffff\">│</span> Hello what can you do? <span style=\"color: #00ffff; text-decoration-color: #00ffff\">│</span>\n",
113+
"<span style=\"color: #00ffff; text-decoration-color: #00ffff\">╰──────────────────────────────────────────────────────────────────────────────╯</span>\n",
114+
"</pre>\n"
115+
],
116+
"text/plain": [
117+
"\u001b[96m╭─\u001b[0m\u001b[96m────────────────────────\u001b[0m\u001b[96m \u001b[0m\u001b[1;96mUSER\u001b[0m\u001b[96m [07/27/2025 00:52:56] \u001b[0m\u001b[96m────────────────────────\u001b[0m\u001b[96m─╮\u001b[0m\n",
118+
"\u001b[96m│\u001b[0m Hello what can you do? \u001b[96m│\u001b[0m\n",
119+
"\u001b[96m╰──────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
120+
]
121+
},
122+
"metadata": {},
123+
"output_type": "display_data"
124+
},
125+
{
126+
"name": "stdout",
127+
"output_type": "stream",
128+
"text": [
129+
" \r"
130+
]
131+
},
132+
{
133+
"data": {
134+
"text/html": [
135+
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #00ff00; text-decoration-color: #00ff00\">╭──────────────────────── </span><span style=\"color: #00ff00; text-decoration-color: #00ff00; font-weight: bold\">AGENT</span><span style=\"color: #00ff00; text-decoration-color: #00ff00\"> [07/27/2025 00:52:56] ─────────────────────────╮</span>\n",
136+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span> Hello! I can assist you with a variety of tasks, such as: <span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span>\n",
137+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span> <span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span>\n",
138+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 1 </span>Answering questions on a wide range of topics, including science, <span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span>\n",
139+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> </span>history, technology, and more. <span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span>\n",
140+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 2 </span>Providing explanations and summaries of complex concepts. <span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span>\n",
141+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 3 </span>Assisting with language translations and grammar checks. <span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span>\n",
142+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 4 </span>Offering writing tips, editing assistance, and brainstorming ideas for <span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span>\n",
143+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> </span>creative projects. <span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span>\n",
144+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 5 </span>Giving advice on studying, time management, and organization. <span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span>\n",
145+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 6 </span>Sharing information about books, movies, and other media. <span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span>\n",
146+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span> <span style=\"color: #808000; text-decoration-color: #808000; font-weight: bold\"> 7 </span>Engaging in general conversation or providing entertainment. <span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span>\n",
147+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span> <span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span>\n",
148+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span> If you have a specific question or need help with something, feel free to <span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span>\n",
149+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span> ask! <span style=\"color: #00ff00; text-decoration-color: #00ff00\">│</span>\n",
150+
"<span style=\"color: #00ff00; text-decoration-color: #00ff00\">╰──────────────────────────────────────────────────────────────────────────────╯</span>\n",
151+
"</pre>\n"
152+
],
153+
"text/plain": [
154+
"\u001b[92m╭─\u001b[0m\u001b[92m───────────────────────\u001b[0m\u001b[92m \u001b[0m\u001b[1;92mAGENT\u001b[0m\u001b[92m [07/27/2025 00:52:56] \u001b[0m\u001b[92m────────────────────────\u001b[0m\u001b[92m─╮\u001b[0m\n",
155+
"\u001b[92m│\u001b[0m Hello! I can assist you with a variety of tasks, such as: \u001b[92m│\u001b[0m\n",
156+
"\u001b[92m│\u001b[0m \u001b[92m│\u001b[0m\n",
157+
"\u001b[92m│\u001b[0m \u001b[1;33m 1 \u001b[0mAnswering questions on a wide range of topics, including science, \u001b[92m│\u001b[0m\n",
158+
"\u001b[92m│\u001b[0m \u001b[1;33m \u001b[0mhistory, technology, and more. \u001b[92m│\u001b[0m\n",
159+
"\u001b[92m│\u001b[0m \u001b[1;33m 2 \u001b[0mProviding explanations and summaries of complex concepts. \u001b[92m│\u001b[0m\n",
160+
"\u001b[92m│\u001b[0m \u001b[1;33m 3 \u001b[0mAssisting with language translations and grammar checks. \u001b[92m│\u001b[0m\n",
161+
"\u001b[92m│\u001b[0m \u001b[1;33m 4 \u001b[0mOffering writing tips, editing assistance, and brainstorming ideas for \u001b[92m│\u001b[0m\n",
162+
"\u001b[92m│\u001b[0m \u001b[1;33m \u001b[0mcreative projects. \u001b[92m│\u001b[0m\n",
163+
"\u001b[92m│\u001b[0m \u001b[1;33m 5 \u001b[0mGiving advice on studying, time management, and organization. \u001b[92m│\u001b[0m\n",
164+
"\u001b[92m│\u001b[0m \u001b[1;33m 6 \u001b[0mSharing information about books, movies, and other media. \u001b[92m│\u001b[0m\n",
165+
"\u001b[92m│\u001b[0m \u001b[1;33m 7 \u001b[0mEngaging in general conversation or providing entertainment. \u001b[92m│\u001b[0m\n",
166+
"\u001b[92m│\u001b[0m \u001b[92m│\u001b[0m\n",
167+
"\u001b[92m│\u001b[0m If you have a specific question or need help with something, feel free to \u001b[92m│\u001b[0m\n",
168+
"\u001b[92m│\u001b[0m ask! \u001b[92m│\u001b[0m\n",
169+
"\u001b[92m╰──────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n"
170+
]
171+
},
172+
"metadata": {},
173+
"output_type": "display_data"
174+
},
175+
{
176+
"name": "stdout",
177+
"output_type": "stream",
178+
"text": [
179+
"Streaming timed out after 5 seconds - returning collected messages\n"
180+
]
181+
}
182+
],
183+
"source": [
184+
"from agentex.lib.utils.dev_tools import subscribe_to_async_task_messages\n",
185+
"\n",
186+
"task_messages = subscribe_to_async_task_messages(\n",
187+
" client=client,\n",
188+
" task=task, \n",
189+
" only_after_timestamp=event.created_at, \n",
190+
" print_messages=True,\n",
191+
" rich_print=True,\n",
192+
" timeout=5,\n",
193+
")"
194+
]
195+
},
196+
{
197+
"cell_type": "code",
198+
"execution_count": null,
199+
"id": "6470ae58",
200+
"metadata": {},
201+
"outputs": [],
202+
"source": []
203+
}
204+
],
205+
"metadata": {
206+
"kernelspec": {
207+
"display_name": ".venv",
208+
"language": "python",
209+
"name": "python3"
210+
},
211+
"language_info": {
212+
"codemirror_mode": {
213+
"name": "ipython",
214+
"version": 3
215+
},
216+
"file_extension": ".py",
217+
"mimetype": "text/x-python",
218+
"name": "python",
219+
"nbconvert_exporter": "python",
220+
"pygments_lexer": "ipython3",
221+
"version": "3.12.9"
222+
}
223+
},
224+
"nbformat": 4,
225+
"nbformat_minor": 5
226+
}

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@ typecheck = { chain = [
121121
requires = ["hatchling==1.26.3", "hatch-fancy-pypi-readme"]
122122
build-backend = "hatchling.build"
123123

124+
[dependency-groups]
125+
dev = [
126+
"ipywidgets>=8.1.7",
127+
"yaspin>=3.1.0",
128+
]
129+
124130
[tool.hatch.build]
125131
include = [
126132
"src/*"

0 commit comments

Comments
 (0)