|
50 | 50 | "id": "3", |
51 | 51 | "metadata": {}, |
52 | 52 | "outputs": [], |
53 | | - "source": "from agentex.lib.utils.dev_tools import subscribe_to_async_task_messages\nfrom agentex.types import Event\nfrom agentex.types.agent_rpc_params import ParamsSendEventRequest\n\n# The response is expected to be a list of TaskMessage objects, which is a union of the following types:\n# - TextContent: A message with just text content \n# - DataContent: A message with JSON-serializable data content\n# - ToolRequestContent: A message with a tool request, which contains a JSON-serializable request to call a tool\n# - ToolResponseContent: A message with a tool response, which contains response object from a tool call in its content\n\n# 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\nconcurrent_event_messages: list[ParamsSendEventRequest] = [\n {\n \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello, what can you do?\"},\n \"task_id\": task.id,\n },\n {\n \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Can you tell me a joke?\"},\n \"task_id\": task.id,\n },\n {\n \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"What is the capital of France?\"},\n \"task_id\": task.id,\n },\n {\n \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Write a short story about a cat\"},\n \"task_id\": task.id,\n },\n {\n \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Tell me how an LLM works\"},\n \"task_id\": task.id,\n },\n]\n\nevents: list[Event] = []\n\nfor event_message in concurrent_event_messages:\n rpc_response = client.agents.send_event(\n agent_name=AGENT_NAME,\n params=event_message\n )\n\n event = rpc_response.result\n events.append(event)\n\nfor event in events:\n print(event)" |
| 53 | + "source": [ |
| 54 | + "from agentex.types import Event\n", |
| 55 | + "from agentex.lib.utils.dev_tools import subscribe_to_async_task_messages\n", |
| 56 | + "from agentex.types.agent_rpc_params import ParamsSendEventRequest\n", |
| 57 | + "\n", |
| 58 | + "# The response is expected to be a list of TaskMessage objects, which is a union of the following types:\n", |
| 59 | + "# - TextContent: A message with just text content \n", |
| 60 | + "# - DataContent: A message with JSON-serializable data content\n", |
| 61 | + "# - ToolRequestContent: A message with a tool request, which contains a JSON-serializable request to call a tool\n", |
| 62 | + "# - ToolResponseContent: A message with a tool response, which contains response object from a tool call in its content\n", |
| 63 | + "\n", |
| 64 | + "# 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", |
| 65 | + "\n", |
| 66 | + "concurrent_event_messages: list[ParamsSendEventRequest] = [\n", |
| 67 | + " {\n", |
| 68 | + " \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello, what can you do?\"},\n", |
| 69 | + " \"task_id\": task.id,\n", |
| 70 | + " },\n", |
| 71 | + " {\n", |
| 72 | + " \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Can you tell me a joke?\"},\n", |
| 73 | + " \"task_id\": task.id,\n", |
| 74 | + " },\n", |
| 75 | + " {\n", |
| 76 | + " \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"What is the capital of France?\"},\n", |
| 77 | + " \"task_id\": task.id,\n", |
| 78 | + " },\n", |
| 79 | + " {\n", |
| 80 | + " \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Write a short story about a cat\"},\n", |
| 81 | + " \"task_id\": task.id,\n", |
| 82 | + " },\n", |
| 83 | + " {\n", |
| 84 | + " \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Tell me how an LLM works\"},\n", |
| 85 | + " \"task_id\": task.id,\n", |
| 86 | + " },\n", |
| 87 | + "]\n", |
| 88 | + "\n", |
| 89 | + "events: list[Event] = []\n", |
| 90 | + "\n", |
| 91 | + "for event_message in concurrent_event_messages:\n", |
| 92 | + " rpc_response = client.agents.send_event(\n", |
| 93 | + " agent_name=AGENT_NAME,\n", |
| 94 | + " params=event_message\n", |
| 95 | + " )\n", |
| 96 | + "\n", |
| 97 | + " event = rpc_response.result\n", |
| 98 | + " events.append(event)\n", |
| 99 | + "\n", |
| 100 | + "for event in events:\n", |
| 101 | + " print(event)" |
| 102 | + ] |
54 | 103 | }, |
55 | 104 | { |
56 | 105 | "cell_type": "code", |
|
0 commit comments