Skip to content

Commit b71fc8e

Browse files
authored
Merge pull request #32 from scaleapi/fs/ag/notebooks2
Fs/ag/notebooks2
2 parents b431b8e + dd198bd commit b71fc8e

File tree

19 files changed

+989
-2048
lines changed

19 files changed

+989
-2048
lines changed

examples/tutorials/00_sync/000_hello_acp/dev.ipynb

Lines changed: 40 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 2,
6-
"id": "36834357",
5+
"execution_count": null,
6+
"id": "0",
77
"metadata": {},
88
"outputs": [],
99
"source": [
@@ -14,8 +14,8 @@
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": 3,
18-
"id": "d1c309d6",
17+
"execution_count": null,
18+
"id": "1",
1919
"metadata": {},
2020
"outputs": [],
2121
"source": [
@@ -24,8 +24,8 @@
2424
},
2525
{
2626
"cell_type": "code",
27-
"execution_count": 4,
28-
"id": "9f6e6ef0",
27+
"execution_count": null,
28+
"id": "2",
2929
"metadata": {},
3030
"outputs": [],
3131
"source": [
@@ -50,22 +50,13 @@
5050
},
5151
{
5252
"cell_type": "code",
53-
"execution_count": 5,
54-
"id": "b03b0d37",
53+
"execution_count": null,
54+
"id": "3",
5555
"metadata": {},
56-
"outputs": [
57-
{
58-
"name": "stdout",
59-
"output_type": "stream",
60-
"text": [
61-
"Hello! I've received your message. Here's a generic response, but in future tutorials we'll see how you can get me to intelligently respond to your message. This is what I heard you say: Hello what can you do?\n"
62-
]
63-
}
64-
],
56+
"outputs": [],
6557
"source": [
6658
"# Test non streaming response\n",
67-
"from typing import List, cast\n",
68-
"from agentex.types import TaskMessage, TextContent\n",
59+
"from agentex.types import TextContent\n",
6960
"\n",
7061
"# The response is expected to be a list of TaskMessage objects, which is a union of the following types:\n",
7162
"# - TextContent: A message with just text content \n",
@@ -75,52 +66,35 @@
7566
"\n",
7667
"# 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",
7768
"\n",
78-
"rpc_response = client.agents.rpc_by_name(\n",
69+
"rpc_response = client.agents.send_message(\n",
7970
" agent_name=AGENT_NAME,\n",
80-
" method=\"message/send\",\n",
8171
" params={\n",
8272
" \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello what can you do?\"},\n",
8373
" \"stream\": False\n",
8474
" }\n",
8575
")\n",
8676
"\n",
87-
"# # Extract and print just the text content from the response\n",
88-
"# # The response is expected to be a dict with a \"result\" key containing a list of message dicts\n",
89-
"if rpc_response and rpc_response.result:\n",
77+
"if not rpc_response or not rpc_response.result:\n",
78+
" raise ValueError(\"No result in response\")\n",
9079
"\n",
91-
" # We know that the result of the message/send when stream is set to False will be a list of TaskMessage objects\n",
92-
" task_message_list = cast(List[TaskMessage], rpc_response.result)\n",
93-
" for task_message in rpc_response.result:\n",
94-
" if isinstance(task_message, TaskMessage):\n",
95-
" content = task_message.content\n",
96-
" if isinstance(content, TextContent):\n",
97-
" text = content.content\n",
98-
" print(text)\n",
99-
" else:\n",
100-
" print(f\"Found non-text {type(task_message)} object in response.\")\n"
80+
"# Extract and print just the text content from the response\n",
81+
"for task_message in rpc_response.result:\n",
82+
" content = task_message.content\n",
83+
" if isinstance(content, TextContent):\n",
84+
" text = content.content\n",
85+
" print(text)\n"
10186
]
10287
},
10388
{
10489
"cell_type": "code",
105-
"execution_count": 6,
106-
"id": "79688331",
90+
"execution_count": null,
91+
"id": "4",
10792
"metadata": {},
108-
"outputs": [
109-
{
110-
"name": "stdout",
111-
"output_type": "stream",
112-
"text": [
113-
"Hello! I've received your message. Here's a generic response, but in future tutorials we'll see how you can get me to intelligently respond to your message. This is what I heard you say: Hello what can you do?\n"
114-
]
115-
}
116-
],
93+
"outputs": [],
11794
"source": [
11895
"# Test streaming response\n",
119-
"import json\n",
120-
"from agentex.types import AgentRpcResponse\n",
121-
"from agentex.types.agent_rpc_result import StreamTaskMessageDelta, StreamTaskMessageFull\n",
96+
"from agentex.types.task_message_update import StreamTaskMessageDelta, StreamTaskMessageFull\n",
12297
"from agentex.types.text_delta import TextDelta\n",
123-
"from agentex.types.task_message_update import TaskMessageUpdate\n",
12498
"\n",
12599
"\n",
126100
"# The result object of message/send will be a TaskMessageUpdate which is a union of the following types:\n",
@@ -136,41 +110,29 @@
136110
"# Whenn processing StreamTaskMessageDelta, if you are expecting more than TextDeltas, such as DataDelta, ToolRequestDelta, or ToolResponseDelta, you can process them as well\n",
137111
"# Whenn processing StreamTaskMessageFull, if you are expecting more than TextContent, such as DataContent, ToolRequestContent, or ToolResponseContent, you can process them as well\n",
138112
"\n",
139-
"with client.agents.with_streaming_response.rpc_by_name(\n",
113+
"for agent_rpc_response_chunk in client.agents.send_message_stream(\n",
140114
" agent_name=AGENT_NAME,\n",
141-
" method=\"message/send\",\n",
142115
" params={\n",
143116
" \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello what can you do?\"},\n",
144117
" \"stream\": True\n",
145118
" }\n",
146-
") as response:\n",
147-
" for agent_rpc_response_str in response.iter_text():\n",
148-
" chunk_rpc_response = AgentRpcResponse.model_validate(json.loads(agent_rpc_response_str))\n",
149-
" # We know that the result of the message/send when stream is set to True will be a TaskMessageUpdate\n",
150-
" task_message_update = cast(TaskMessageUpdate, chunk_rpc_response.result)\n",
151-
"\n",
152-
" # Print oly the text deltas as they arrive or any full messages\n",
153-
" if isinstance(task_message_update, StreamTaskMessageDelta):\n",
154-
" delta = task_message_update.delta\n",
155-
" if isinstance(delta, TextDelta):\n",
156-
" print(delta.text_delta, end=\"\", flush=True)\n",
157-
" else:\n",
158-
" print(f\"Found non-text {type(task_message)} object in streaming message.\")\n",
159-
" elif isinstance(task_message_update, StreamTaskMessageFull):\n",
160-
" content = task_message_update.content\n",
161-
" if isinstance(content, TextContent):\n",
162-
" print(content.content)\n",
163-
" else:\n",
164-
" print(f\"Found non-text {type(task_message)} object in full message.\")\n"
119+
"):\n",
120+
" # We know that the result of the message/send when stream is set to True will be a TaskMessageUpdate\n",
121+
" task_message_update = agent_rpc_response_chunk.result\n",
122+
" # Print oly the text deltas as they arrive or any full messages\n",
123+
" if isinstance(task_message_update, StreamTaskMessageDelta):\n",
124+
" delta = task_message_update.delta\n",
125+
" if isinstance(delta, TextDelta):\n",
126+
" print(delta.text_delta, end=\"\", flush=True)\n",
127+
" else:\n",
128+
" print(f\"Found non-text {type(task_message)} object in streaming message.\")\n",
129+
" elif isinstance(task_message_update, StreamTaskMessageFull):\n",
130+
" content = task_message_update.content\n",
131+
" if isinstance(content, TextContent):\n",
132+
" print(content.content)\n",
133+
" else:\n",
134+
" print(f\"Found non-text {type(task_message)} object in full message.\")\n"
165135
]
166-
},
167-
{
168-
"cell_type": "code",
169-
"execution_count": null,
170-
"id": "568673bf",
171-
"metadata": {},
172-
"outputs": [],
173-
"source": []
174136
}
175137
],
176138
"metadata": {

examples/tutorials/00_sync/010_multiturn/dev.ipynb

Lines changed: 41 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 2,
6-
"id": "36834357",
5+
"execution_count": null,
6+
"id": "0",
77
"metadata": {},
88
"outputs": [],
99
"source": [
@@ -14,8 +14,8 @@
1414
},
1515
{
1616
"cell_type": "code",
17-
"execution_count": 3,
18-
"id": "d1c309d6",
17+
"execution_count": null,
18+
"id": "1",
1919
"metadata": {},
2020
"outputs": [],
2121
"source": [
@@ -24,8 +24,8 @@
2424
},
2525
{
2626
"cell_type": "code",
27-
"execution_count": 4,
28-
"id": "9f6e6ef0",
27+
"execution_count": null,
28+
"id": "2",
2929
"metadata": {},
3030
"outputs": [],
3131
"source": [
@@ -50,30 +50,13 @@
5050
},
5151
{
5252
"cell_type": "code",
53-
"execution_count": 5,
54-
"id": "b03b0d37",
53+
"execution_count": null,
54+
"id": "3",
5555
"metadata": {},
56-
"outputs": [
57-
{
58-
"name": "stdout",
59-
"output_type": "stream",
60-
"text": [
61-
"Hello! I can assist you with a variety of tasks, including:\n",
62-
"\n",
63-
"1. Answering questions on a wide range of topics, including science, history, technology, and more.\n",
64-
"2. Providing explanations or summaries of complex concepts.\n",
65-
"3. Offering writing assistance, such as proofreading, editing, or generating ideas for essays and articles.\n",
66-
"4. Helping with problem-solving in areas like math, coding, or logic puzzles.\n",
67-
"5. Engaging in conversation to provide companionship or entertainment.\n",
68-
"\n",
69-
"If there's something specific you need help with, feel free to ask!\n"
70-
]
71-
}
72-
],
56+
"outputs": [],
7357
"source": [
7458
"# Test non streaming response\n",
75-
"from typing import List, cast\n",
76-
"from agentex.types import TaskMessage, TextContent\n",
59+
"from agentex.types import TextContent\n",
7760
"\n",
7861
"# The response is expected to be a list of TaskMessage objects, which is a union of the following types:\n",
7962
"# - TextContent: A message with just text content \n",
@@ -83,61 +66,35 @@
8366
"\n",
8467
"# 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",
8568
"\n",
86-
"rpc_response = client.agents.rpc_by_name(\n",
69+
"rpc_response = client.agents.send_message(\n",
8770
" agent_name=AGENT_NAME,\n",
88-
" method=\"message/send\",\n",
8971
" params={\n",
9072
" \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello what can you do?\"},\n",
9173
" \"stream\": False\n",
9274
" }\n",
9375
")\n",
9476
"\n",
95-
"# # Extract and print just the text content from the response\n",
96-
"# # The response is expected to be a dict with a \"result\" key containing a list of message dicts\n",
97-
"if rpc_response and rpc_response.result:\n",
77+
"if not rpc_response or not rpc_response.result:\n",
78+
" raise ValueError(\"No result in response\")\n",
9879
"\n",
99-
" # We know that the result of the message/send when stream is set to False will be a list of TaskMessage objects\n",
100-
" task_message_list = cast(List[TaskMessage], rpc_response.result)\n",
101-
" for task_message in rpc_response.result:\n",
102-
" if isinstance(task_message, TaskMessage):\n",
103-
" content = task_message.content\n",
104-
" if isinstance(content, TextContent):\n",
105-
" text = content.content\n",
106-
" print(text)\n",
107-
" else:\n",
108-
" print(f\"Found non-text {type(task_message)} object in response.\")\n"
80+
"# Extract and print just the text content from the response\n",
81+
"for task_message in rpc_response.result:\n",
82+
" content = task_message.content\n",
83+
" if isinstance(content, TextContent):\n",
84+
" text = content.content\n",
85+
" print(text)\n"
10986
]
11087
},
11188
{
11289
"cell_type": "code",
113-
"execution_count": 6,
114-
"id": "79688331",
90+
"execution_count": null,
91+
"id": "4",
11592
"metadata": {},
116-
"outputs": [
117-
{
118-
"name": "stdout",
119-
"output_type": "stream",
120-
"text": [
121-
"Hello! I can assist you with a wide range of tasks, including:\n",
122-
"\n",
123-
"1. **Answering questions**: I can provide information on a variety of topics, including history, science, technology, and more.\n",
124-
"2. **Learning and education**: I can help explain concepts, provide summaries, and assist with studying.\n",
125-
"3. **Writing assistance**: I can help you draft, edit, or brainstorm ideas for essays, reports, and creative writing.\n",
126-
"4. **Programming help**: I can assist with coding questions, debugging, and providing explanations of programming concepts.\n",
127-
"5. **Language translation**: I can translate text between several languages.\n",
128-
"6. **General advice**: I can offer suggestions on topics like time management, study techniques, and more.\n",
129-
"\n",
130-
"Feel free to ask me anything specific you need help with!\n"
131-
]
132-
}
133-
],
93+
"outputs": [],
13494
"source": [
13595
"# Test streaming response\n",
136-
"import json\n",
137-
"from agentex.types import AgentRpcResponse\n",
138-
"from agentex.types.agent_rpc_result import StreamTaskMessageDelta, StreamTaskMessageFull\n",
96+
"from agentex.types.task_message_update import StreamTaskMessageDelta, StreamTaskMessageFull\n",
13997
"from agentex.types.text_delta import TextDelta\n",
140-
"from agentex.types.task_message_update import TaskMessageUpdate\n",
14198
"\n",
14299
"\n",
143100
"# The result object of message/send will be a TaskMessageUpdate which is a union of the following types:\n",
@@ -153,38 +110,34 @@
153110
"# Whenn processing StreamTaskMessageDelta, if you are expecting more than TextDeltas, such as DataDelta, ToolRequestDelta, or ToolResponseDelta, you can process them as well\n",
154111
"# Whenn processing StreamTaskMessageFull, if you are expecting more than TextContent, such as DataContent, ToolRequestContent, or ToolResponseContent, you can process them as well\n",
155112
"\n",
156-
"with client.agents.with_streaming_response.rpc_by_name(\n",
113+
"for agent_rpc_response_chunk in client.agents.send_message_stream(\n",
157114
" agent_name=AGENT_NAME,\n",
158-
" method=\"message/send\",\n",
159115
" params={\n",
160116
" \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello what can you do?\"},\n",
161117
" \"stream\": True\n",
162118
" }\n",
163-
") as response:\n",
164-
" for agent_rpc_response_str in response.iter_text():\n",
165-
" chunk_rpc_response = AgentRpcResponse.model_validate(json.loads(agent_rpc_response_str))\n",
166-
" # We know that the result of the message/send when stream is set to True will be a TaskMessageUpdate\n",
167-
" task_message_update = cast(TaskMessageUpdate, chunk_rpc_response.result)\n",
168-
"\n",
169-
" # Print oly the text deltas as they arrive or any full messages\n",
170-
" if isinstance(task_message_update, StreamTaskMessageDelta):\n",
171-
" delta = task_message_update.delta\n",
172-
" if isinstance(delta, TextDelta):\n",
173-
" print(delta.text_delta, end=\"\", flush=True)\n",
174-
" else:\n",
175-
" print(f\"Found non-text {type(task_message)} object in streaming message.\")\n",
176-
" elif isinstance(task_message_update, StreamTaskMessageFull):\n",
177-
" content = task_message_update.content\n",
178-
" if isinstance(content, TextContent):\n",
179-
" print(content.content)\n",
180-
" else:\n",
181-
" print(f\"Found non-text {type(task_message)} object in full message.\")\n"
119+
"):\n",
120+
" # We know that the result of the message/send when stream is set to True will be a TaskMessageUpdate\n",
121+
" task_message_update = agent_rpc_response_chunk.result\n",
122+
" # Print oly the text deltas as they arrive or any full messages\n",
123+
" if isinstance(task_message_update, StreamTaskMessageDelta):\n",
124+
" delta = task_message_update.delta\n",
125+
" if isinstance(delta, TextDelta):\n",
126+
" print(delta.text_delta, end=\"\", flush=True)\n",
127+
" else:\n",
128+
" print(f\"Found non-text {type(task_message)} object in streaming message.\")\n",
129+
" elif isinstance(task_message_update, StreamTaskMessageFull):\n",
130+
" content = task_message_update.content\n",
131+
" if isinstance(content, TextContent):\n",
132+
" print(content.content)\n",
133+
" else:\n",
134+
" print(f\"Found non-text {type(task_message)} object in full message.\")\n"
182135
]
183136
},
184137
{
185138
"cell_type": "code",
186139
"execution_count": null,
187-
"id": "42689ee4",
140+
"id": "5",
188141
"metadata": {},
189142
"outputs": [],
190143
"source": []

0 commit comments

Comments
 (0)