|
2 | 2 | "cells": [ |
3 | 3 | { |
4 | 4 | "cell_type": "code", |
5 | | - "execution_count": null, |
| 5 | + "execution_count": 1, |
6 | 6 | "id": "36834357", |
7 | 7 | "metadata": {}, |
8 | 8 | "outputs": [], |
|
14 | 14 | }, |
15 | 15 | { |
16 | 16 | "cell_type": "code", |
17 | | - "execution_count": null, |
| 17 | + "execution_count": 2, |
18 | 18 | "id": "d1c309d6", |
19 | 19 | "metadata": {}, |
20 | 20 | "outputs": [], |
|
24 | 24 | }, |
25 | 25 | { |
26 | 26 | "cell_type": "code", |
27 | | - "execution_count": null, |
| 27 | + "execution_count": 3, |
28 | 28 | "id": "9f6e6ef0", |
29 | 29 | "metadata": {}, |
30 | | - "outputs": [], |
| 30 | + "outputs": [ |
| 31 | + { |
| 32 | + "name": "stdout", |
| 33 | + "output_type": "stream", |
| 34 | + "text": [ |
| 35 | + "Task(id='83aeec42-3e63-4652-aff5-506252e7cb67', created_at=datetime.datetime(2025, 7, 27, 5, 56, 44, 321516, tzinfo=TzInfo(UTC)), name='776014ce-task', status='RUNNING', status_reason='Task created, forwarding to ACP server', updated_at=datetime.datetime(2025, 7, 27, 5, 56, 44, 321516, tzinfo=TzInfo(UTC)))\n" |
| 36 | + ] |
| 37 | + } |
| 38 | + ], |
31 | 39 | "source": [ |
32 | 40 | "# (REQUIRED) Create a new task. For Agentic agents, you must create a task for messages to be associated with.\n", |
33 | 41 | "\n", |
|
53 | 61 | }, |
54 | 62 | { |
55 | 63 | "cell_type": "code", |
56 | | - "execution_count": null, |
| 64 | + "execution_count": 6, |
57 | 65 | "id": "b03b0d37", |
58 | 66 | "metadata": {}, |
59 | | - "outputs": [], |
| 67 | + "outputs": [ |
| 68 | + { |
| 69 | + "name": "stdout", |
| 70 | + "output_type": "stream", |
| 71 | + "text": [ |
| 72 | + "Event(id='f83319aa-6f63-4495-be1e-6ca52595e865', agent_id='406f9f42-9f3f-4bb2-869c-d6b36028e487', sequence_id=225, task_id='83aeec42-3e63-4652-aff5-506252e7cb67', 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, 6, 0, 8, 557860, tzinfo=TzInfo(UTC)))\n", |
| 73 | + "Event(id='be4b68b3-991a-4dfe-8be5-31f1cc032ef1', agent_id='406f9f42-9f3f-4bb2-869c-d6b36028e487', sequence_id=226, task_id='83aeec42-3e63-4652-aff5-506252e7cb67', content=TextContent(author='user', content='Can you tell me a joke?', attachments=None, format='plain', style='static', type='text'), created_at=datetime.datetime(2025, 7, 27, 6, 0, 8, 615897, tzinfo=TzInfo(UTC)))\n", |
| 74 | + "Event(id='3001a88f-de80-44bf-b2ff-686428da043b', agent_id='406f9f42-9f3f-4bb2-869c-d6b36028e487', sequence_id=227, task_id='83aeec42-3e63-4652-aff5-506252e7cb67', content=TextContent(author='user', content='What is the capital of France?', attachments=None, format='plain', style='static', type='text'), created_at=datetime.datetime(2025, 7, 27, 6, 0, 8, 665333, tzinfo=TzInfo(UTC)))\n", |
| 75 | + "Event(id='49ca99da-1c88-41f3-abea-91845cd927d5', agent_id='406f9f42-9f3f-4bb2-869c-d6b36028e487', sequence_id=228, task_id='83aeec42-3e63-4652-aff5-506252e7cb67', content=TextContent(author='user', content='Write a short story about a cat', attachments=None, format='plain', style='static', type='text'), created_at=datetime.datetime(2025, 7, 27, 6, 0, 8, 704690, tzinfo=TzInfo(UTC)))\n", |
| 76 | + "Event(id='da567964-5fa6-419d-a573-66e673f18669', agent_id='406f9f42-9f3f-4bb2-869c-d6b36028e487', sequence_id=229, task_id='83aeec42-3e63-4652-aff5-506252e7cb67', content=TextContent(author='user', content='Tell me how an LLM works', attachments=None, format='plain', style='static', type='text'), created_at=datetime.datetime(2025, 7, 27, 6, 0, 8, 748329, tzinfo=TzInfo(UTC)))\n" |
| 77 | + ] |
| 78 | + } |
| 79 | + ], |
60 | 80 | "source": [ |
61 | 81 | "# Test non streaming response\n", |
62 | 82 | "from typing import cast\n", |
63 | 83 | "from agentex.types import Event\n", |
| 84 | + "from agentex.types.agent_rpc_params import ParamsSendEventRequest\n", |
64 | 85 | "\n", |
65 | 86 | "# The response is expected to be a list of TaskMessage objects, which is a union of the following types:\n", |
66 | 87 | "# - TextContent: A message with just text content \n", |
|
70 | 91 | "\n", |
71 | 92 | "# 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", |
72 | 93 | "\n", |
73 | | - "rpc_response = client.agents.rpc_by_name(\n", |
74 | | - " agent_name=AGENT_NAME,\n", |
75 | | - " method=\"event/send\",\n", |
76 | | - " params={\n", |
77 | | - " \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello what can you do?\"},\n", |
| 94 | + "concurrent_event_messages: list[ParamsSendEventRequest] = [\n", |
| 95 | + " {\n", |
| 96 | + " \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello, what can you do?\"},\n", |
78 | 97 | " \"task_id\": task.id,\n", |
79 | | - " }\n", |
80 | | - ")\n", |
| 98 | + " },\n", |
| 99 | + " {\n", |
| 100 | + " \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Can you tell me a joke?\"},\n", |
| 101 | + " \"task_id\": task.id,\n", |
| 102 | + " },\n", |
| 103 | + " {\n", |
| 104 | + " \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"What is the capital of France?\"},\n", |
| 105 | + " \"task_id\": task.id,\n", |
| 106 | + " },\n", |
| 107 | + " {\n", |
| 108 | + " \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Write a short story about a cat\"},\n", |
| 109 | + " \"task_id\": task.id,\n", |
| 110 | + " },\n", |
| 111 | + " {\n", |
| 112 | + " \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Tell me how an LLM works\"},\n", |
| 113 | + " \"task_id\": task.id,\n", |
| 114 | + " },\n", |
| 115 | + "]\n", |
| 116 | + "\n", |
| 117 | + "events: list[Event] = []\n", |
| 118 | + "\n", |
| 119 | + "for event_message in concurrent_event_messages:\n", |
| 120 | + " rpc_response = client.agents.rpc_by_name(\n", |
| 121 | + " agent_name=AGENT_NAME,\n", |
| 122 | + " method=\"event/send\",\n", |
| 123 | + " params=event_message\n", |
| 124 | + " )\n", |
81 | 125 | "\n", |
82 | | - "event = cast(Event, rpc_response.result)\n", |
83 | | - "print(event)" |
| 126 | + " event = cast(Event, rpc_response.result)\n", |
| 127 | + " events.append(event)\n", |
| 128 | + "\n", |
| 129 | + "for event in events:\n", |
| 130 | + " print(event)" |
84 | 131 | ] |
85 | 132 | }, |
86 | 133 | { |
87 | 134 | "cell_type": "code", |
88 | | - "execution_count": null, |
| 135 | + "execution_count": 7, |
89 | 136 | "id": "a6927cc0", |
90 | 137 | "metadata": {}, |
91 | | - "outputs": [], |
| 138 | + "outputs": [ |
| 139 | + { |
| 140 | + "data": { |
| 141 | + "text/html": [ |
| 142 | + "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">╭──────────────────────── </span><span style=\"color: #008000; text-decoration-color: #008000; font-weight: bold\">AGENT</span><span style=\"color: #008000; text-decoration-color: #008000\"> [07/27/2025 06:00:18] ─────────────────────────╮</span>\n", |
| 143 | + "<span style=\"color: #008000; text-decoration-color: #008000\">│</span> Processed event IDs: ['f83319aa-6f63-4495-be1e-6ca52595e865', <span style=\"color: #008000; text-decoration-color: #008000\">│</span>\n", |
| 144 | + "<span style=\"color: #008000; text-decoration-color: #008000\">│</span> 'be4b68b3-991a-4dfe-8be5-31f1cc032ef1'] <span style=\"color: #008000; text-decoration-color: #008000\">│</span>\n", |
| 145 | + "<span style=\"color: #008000; text-decoration-color: #008000\">╰──────────────────────────────────────────────────────────────────────────────╯</span>\n", |
| 146 | + "</pre>\n" |
| 147 | + ], |
| 148 | + "text/plain": [ |
| 149 | + "\u001b[32m╭─\u001b[0m\u001b[32m───────────────────────\u001b[0m\u001b[32m \u001b[0m\u001b[1;32mAGENT\u001b[0m\u001b[32m [07/27/2025 06:00:18] \u001b[0m\u001b[32m────────────────────────\u001b[0m\u001b[32m─╮\u001b[0m\n", |
| 150 | + "\u001b[32m│\u001b[0m Processed event IDs: ['f83319aa-6f63-4495-be1e-6ca52595e865', \u001b[32m│\u001b[0m\n", |
| 151 | + "\u001b[32m│\u001b[0m 'be4b68b3-991a-4dfe-8be5-31f1cc032ef1'] \u001b[32m│\u001b[0m\n", |
| 152 | + "\u001b[32m╰──────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n" |
| 153 | + ] |
| 154 | + }, |
| 155 | + "metadata": {}, |
| 156 | + "output_type": "display_data" |
| 157 | + }, |
| 158 | + { |
| 159 | + "data": { |
| 160 | + "text/html": [ |
| 161 | + "<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"color: #008000; text-decoration-color: #008000\">╭──────────────────────── </span><span style=\"color: #008000; text-decoration-color: #008000; font-weight: bold\">AGENT</span><span style=\"color: #008000; text-decoration-color: #008000\"> [07/27/2025 06:00:33] ─────────────────────────╮</span>\n", |
| 162 | + "<span style=\"color: #008000; text-decoration-color: #008000\">│</span> Processed event IDs: ['3001a88f-de80-44bf-b2ff-686428da043b', <span style=\"color: #008000; text-decoration-color: #008000\">│</span>\n", |
| 163 | + "<span style=\"color: #008000; text-decoration-color: #008000\">│</span> '49ca99da-1c88-41f3-abea-91845cd927d5', <span style=\"color: #008000; text-decoration-color: #008000\">│</span>\n", |
| 164 | + "<span style=\"color: #008000; text-decoration-color: #008000\">│</span> 'da567964-5fa6-419d-a573-66e673f18669'] <span style=\"color: #008000; text-decoration-color: #008000\">│</span>\n", |
| 165 | + "<span style=\"color: #008000; text-decoration-color: #008000\">╰──────────────────────────────────────────────────────────────────────────────╯</span>\n", |
| 166 | + "</pre>\n" |
| 167 | + ], |
| 168 | + "text/plain": [ |
| 169 | + "\u001b[32m╭─\u001b[0m\u001b[32m───────────────────────\u001b[0m\u001b[32m \u001b[0m\u001b[1;32mAGENT\u001b[0m\u001b[32m [07/27/2025 06:00:33] \u001b[0m\u001b[32m────────────────────────\u001b[0m\u001b[32m─╮\u001b[0m\n", |
| 170 | + "\u001b[32m│\u001b[0m Processed event IDs: ['3001a88f-de80-44bf-b2ff-686428da043b', \u001b[32m│\u001b[0m\n", |
| 171 | + "\u001b[32m│\u001b[0m '49ca99da-1c88-41f3-abea-91845cd927d5', \u001b[32m│\u001b[0m\n", |
| 172 | + "\u001b[32m│\u001b[0m 'da567964-5fa6-419d-a573-66e673f18669'] \u001b[32m│\u001b[0m\n", |
| 173 | + "\u001b[32m╰──────────────────────────────────────────────────────────────────────────────╯\u001b[0m\n" |
| 174 | + ] |
| 175 | + }, |
| 176 | + "metadata": {}, |
| 177 | + "output_type": "display_data" |
| 178 | + }, |
| 179 | + { |
| 180 | + "name": "stdout", |
| 181 | + "output_type": "stream", |
| 182 | + "text": [ |
| 183 | + "Streaming timed out after 20 seconds - returning collected messages\n" |
| 184 | + ] |
| 185 | + } |
| 186 | + ], |
92 | 187 | "source": [ |
93 | 188 | "from agentex.lib.utils.dev_tools import subscribe_to_async_task_messages\n", |
94 | 189 | "\n", |
|
98 | 193 | " only_after_timestamp=event.created_at, \n", |
99 | 194 | " print_messages=True,\n", |
100 | 195 | " rich_print=True,\n", |
101 | | - " timeout=5,\n", |
| 196 | + " timeout=20,\n", |
102 | 197 | ")" |
103 | 198 | ] |
| 199 | + }, |
| 200 | + { |
| 201 | + "cell_type": "code", |
| 202 | + "execution_count": null, |
| 203 | + "id": "593a0a47", |
| 204 | + "metadata": {}, |
| 205 | + "outputs": [], |
| 206 | + "source": [] |
104 | 207 | } |
105 | 208 | ], |
106 | 209 | "metadata": { |
|
0 commit comments