Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 40 additions & 78 deletions examples/tutorials/00_sync/000_hello_acp/dev.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "36834357",
"execution_count": null,
"id": "0",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -14,8 +14,8 @@
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d1c309d6",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -24,8 +24,8 @@
},
{
"cell_type": "code",
"execution_count": 4,
"id": "9f6e6ef0",
"execution_count": null,
"id": "2",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -50,22 +50,13 @@
},
{
"cell_type": "code",
"execution_count": 5,
"id": "b03b0d37",
"execution_count": null,
"id": "3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"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"
]
}
],
"outputs": [],
"source": [
"# Test non streaming response\n",
"from typing import List, cast\n",
"from agentex.types import TaskMessage, TextContent\n",
"from agentex.types import TextContent\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",
Expand All @@ -75,52 +66,35 @@
"\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",
"\n",
"rpc_response = client.agents.rpc_by_name(\n",
"rpc_response = client.agents.send_message(\n",
" agent_name=AGENT_NAME,\n",
" method=\"message/send\",\n",
" params={\n",
" \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello what can you do?\"},\n",
" \"stream\": False\n",
" }\n",
")\n",
"\n",
"# # Extract and print just the text content from the response\n",
"# # The response is expected to be a dict with a \"result\" key containing a list of message dicts\n",
"if rpc_response and rpc_response.result:\n",
"if not rpc_response or not rpc_response.result:\n",
" raise ValueError(\"No result in response\")\n",
"\n",
" # We know that the result of the message/send when stream is set to False will be a list of TaskMessage objects\n",
" task_message_list = cast(List[TaskMessage], rpc_response.result)\n",
" for task_message in rpc_response.result:\n",
" if isinstance(task_message, TaskMessage):\n",
" content = task_message.content\n",
" if isinstance(content, TextContent):\n",
" text = content.content\n",
" print(text)\n",
" else:\n",
" print(f\"Found non-text {type(task_message)} object in response.\")\n"
"# Extract and print just the text content from the response\n",
"for task_message in rpc_response.result:\n",
" content = task_message.content\n",
" if isinstance(content, TextContent):\n",
" text = content.content\n",
" print(text)\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "79688331",
"execution_count": null,
"id": "4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"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"
]
}
],
"outputs": [],
"source": [
"# Test streaming response\n",
"import json\n",
"from agentex.types import AgentRpcResponse\n",
"from agentex.types.agent_rpc_result import StreamTaskMessageDelta, StreamTaskMessageFull\n",
"from agentex.types.task_message_update import StreamTaskMessageDelta, StreamTaskMessageFull\n",
"from agentex.types.text_delta import TextDelta\n",
"from agentex.types.task_message_update import TaskMessageUpdate\n",
"\n",
"\n",
"# The result object of message/send will be a TaskMessageUpdate which is a union of the following types:\n",
Expand All @@ -136,41 +110,29 @@
"# Whenn processing StreamTaskMessageDelta, if you are expecting more than TextDeltas, such as DataDelta, ToolRequestDelta, or ToolResponseDelta, you can process them as well\n",
"# Whenn processing StreamTaskMessageFull, if you are expecting more than TextContent, such as DataContent, ToolRequestContent, or ToolResponseContent, you can process them as well\n",
"\n",
"with client.agents.with_streaming_response.rpc_by_name(\n",
"for agent_rpc_response_chunk in client.agents.send_message_stream(\n",
" agent_name=AGENT_NAME,\n",
" method=\"message/send\",\n",
" params={\n",
" \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello what can you do?\"},\n",
" \"stream\": True\n",
" }\n",
") as response:\n",
" for agent_rpc_response_str in response.iter_text():\n",
" chunk_rpc_response = AgentRpcResponse.model_validate(json.loads(agent_rpc_response_str))\n",
" # We know that the result of the message/send when stream is set to True will be a TaskMessageUpdate\n",
" task_message_update = cast(TaskMessageUpdate, chunk_rpc_response.result)\n",
"\n",
" # Print oly the text deltas as they arrive or any full messages\n",
" if isinstance(task_message_update, StreamTaskMessageDelta):\n",
" delta = task_message_update.delta\n",
" if isinstance(delta, TextDelta):\n",
" print(delta.text_delta, end=\"\", flush=True)\n",
" else:\n",
" print(f\"Found non-text {type(task_message)} object in streaming message.\")\n",
" elif isinstance(task_message_update, StreamTaskMessageFull):\n",
" content = task_message_update.content\n",
" if isinstance(content, TextContent):\n",
" print(content.content)\n",
" else:\n",
" print(f\"Found non-text {type(task_message)} object in full message.\")\n"
"):\n",
" # We know that the result of the message/send when stream is set to True will be a TaskMessageUpdate\n",
" task_message_update = agent_rpc_response_chunk.result\n",
" # Print oly the text deltas as they arrive or any full messages\n",
" if isinstance(task_message_update, StreamTaskMessageDelta):\n",
" delta = task_message_update.delta\n",
" if isinstance(delta, TextDelta):\n",
" print(delta.text_delta, end=\"\", flush=True)\n",
" else:\n",
" print(f\"Found non-text {type(task_message)} object in streaming message.\")\n",
" elif isinstance(task_message_update, StreamTaskMessageFull):\n",
" content = task_message_update.content\n",
" if isinstance(content, TextContent):\n",
" print(content.content)\n",
" else:\n",
" print(f\"Found non-text {type(task_message)} object in full message.\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "568673bf",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
129 changes: 41 additions & 88 deletions examples/tutorials/00_sync/010_multiturn/dev.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "36834357",
"execution_count": null,
"id": "0",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -14,8 +14,8 @@
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d1c309d6",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -24,8 +24,8 @@
},
{
"cell_type": "code",
"execution_count": 4,
"id": "9f6e6ef0",
"execution_count": null,
"id": "2",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -50,30 +50,13 @@
},
{
"cell_type": "code",
"execution_count": 5,
"id": "b03b0d37",
"execution_count": null,
"id": "3",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello! I can assist you with a variety of tasks, including:\n",
"\n",
"1. Answering questions on a wide range of topics, including science, history, technology, and more.\n",
"2. Providing explanations or summaries of complex concepts.\n",
"3. Offering writing assistance, such as proofreading, editing, or generating ideas for essays and articles.\n",
"4. Helping with problem-solving in areas like math, coding, or logic puzzles.\n",
"5. Engaging in conversation to provide companionship or entertainment.\n",
"\n",
"If there's something specific you need help with, feel free to ask!\n"
]
}
],
"outputs": [],
"source": [
"# Test non streaming response\n",
"from typing import List, cast\n",
"from agentex.types import TaskMessage, TextContent\n",
"from agentex.types import TextContent\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",
Expand All @@ -83,61 +66,35 @@
"\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",
"\n",
"rpc_response = client.agents.rpc_by_name(\n",
"rpc_response = client.agents.send_message(\n",
" agent_name=AGENT_NAME,\n",
" method=\"message/send\",\n",
" params={\n",
" \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello what can you do?\"},\n",
" \"stream\": False\n",
" }\n",
")\n",
"\n",
"# # Extract and print just the text content from the response\n",
"# # The response is expected to be a dict with a \"result\" key containing a list of message dicts\n",
"if rpc_response and rpc_response.result:\n",
"if not rpc_response or not rpc_response.result:\n",
" raise ValueError(\"No result in response\")\n",
"\n",
" # We know that the result of the message/send when stream is set to False will be a list of TaskMessage objects\n",
" task_message_list = cast(List[TaskMessage], rpc_response.result)\n",
" for task_message in rpc_response.result:\n",
" if isinstance(task_message, TaskMessage):\n",
" content = task_message.content\n",
" if isinstance(content, TextContent):\n",
" text = content.content\n",
" print(text)\n",
" else:\n",
" print(f\"Found non-text {type(task_message)} object in response.\")\n"
"# Extract and print just the text content from the response\n",
"for task_message in rpc_response.result:\n",
" content = task_message.content\n",
" if isinstance(content, TextContent):\n",
" text = content.content\n",
" print(text)\n"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "79688331",
"execution_count": null,
"id": "4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello! I can assist you with a wide range of tasks, including:\n",
"\n",
"1. **Answering questions**: I can provide information on a variety of topics, including history, science, technology, and more.\n",
"2. **Learning and education**: I can help explain concepts, provide summaries, and assist with studying.\n",
"3. **Writing assistance**: I can help you draft, edit, or brainstorm ideas for essays, reports, and creative writing.\n",
"4. **Programming help**: I can assist with coding questions, debugging, and providing explanations of programming concepts.\n",
"5. **Language translation**: I can translate text between several languages.\n",
"6. **General advice**: I can offer suggestions on topics like time management, study techniques, and more.\n",
"\n",
"Feel free to ask me anything specific you need help with!\n"
]
}
],
"outputs": [],
"source": [
"# Test streaming response\n",
"import json\n",
"from agentex.types import AgentRpcResponse\n",
"from agentex.types.agent_rpc_result import StreamTaskMessageDelta, StreamTaskMessageFull\n",
"from agentex.types.task_message_update import StreamTaskMessageDelta, StreamTaskMessageFull\n",
"from agentex.types.text_delta import TextDelta\n",
"from agentex.types.task_message_update import TaskMessageUpdate\n",
"\n",
"\n",
"# The result object of message/send will be a TaskMessageUpdate which is a union of the following types:\n",
Expand All @@ -153,38 +110,34 @@
"# Whenn processing StreamTaskMessageDelta, if you are expecting more than TextDeltas, such as DataDelta, ToolRequestDelta, or ToolResponseDelta, you can process them as well\n",
"# Whenn processing StreamTaskMessageFull, if you are expecting more than TextContent, such as DataContent, ToolRequestContent, or ToolResponseContent, you can process them as well\n",
"\n",
"with client.agents.with_streaming_response.rpc_by_name(\n",
"for agent_rpc_response_chunk in client.agents.send_message_stream(\n",
" agent_name=AGENT_NAME,\n",
" method=\"message/send\",\n",
" params={\n",
" \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello what can you do?\"},\n",
" \"stream\": True\n",
" }\n",
") as response:\n",
" for agent_rpc_response_str in response.iter_text():\n",
" chunk_rpc_response = AgentRpcResponse.model_validate(json.loads(agent_rpc_response_str))\n",
" # We know that the result of the message/send when stream is set to True will be a TaskMessageUpdate\n",
" task_message_update = cast(TaskMessageUpdate, chunk_rpc_response.result)\n",
"\n",
" # Print oly the text deltas as they arrive or any full messages\n",
" if isinstance(task_message_update, StreamTaskMessageDelta):\n",
" delta = task_message_update.delta\n",
" if isinstance(delta, TextDelta):\n",
" print(delta.text_delta, end=\"\", flush=True)\n",
" else:\n",
" print(f\"Found non-text {type(task_message)} object in streaming message.\")\n",
" elif isinstance(task_message_update, StreamTaskMessageFull):\n",
" content = task_message_update.content\n",
" if isinstance(content, TextContent):\n",
" print(content.content)\n",
" else:\n",
" print(f\"Found non-text {type(task_message)} object in full message.\")\n"
"):\n",
" # We know that the result of the message/send when stream is set to True will be a TaskMessageUpdate\n",
" task_message_update = agent_rpc_response_chunk.result\n",
" # Print oly the text deltas as they arrive or any full messages\n",
" if isinstance(task_message_update, StreamTaskMessageDelta):\n",
" delta = task_message_update.delta\n",
" if isinstance(delta, TextDelta):\n",
" print(delta.text_delta, end=\"\", flush=True)\n",
" else:\n",
" print(f\"Found non-text {type(task_message)} object in streaming message.\")\n",
" elif isinstance(task_message_update, StreamTaskMessageFull):\n",
" content = task_message_update.content\n",
" if isinstance(content, TextContent):\n",
" print(content.content)\n",
" else:\n",
" print(f\"Found non-text {type(task_message)} object in full message.\")\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "42689ee4",
"id": "5",
"metadata": {},
"outputs": [],
"source": []
Expand Down
Loading
Loading