agentex-sdk 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agentex/_version.py +1 -1
- agentex/lib/adk/_modules/messages.py +2 -2
- agentex/lib/adk/_modules/streaming.py +2 -2
- agentex/lib/adk/providers/_modules/litellm.py +2 -2
- agentex/lib/adk/providers/_modules/openai.py +2 -2
- agentex/lib/cli/commands/init.py +8 -4
- agentex/lib/cli/templates/default/README.md.j2 +23 -2
- agentex/lib/cli/templates/default/dev.ipynb.j2 +127 -0
- agentex/lib/cli/templates/sync/README.md.j2 +22 -2
- agentex/lib/cli/templates/sync/dev.ipynb.j2 +181 -0
- agentex/lib/cli/templates/sync/project/acp.py.j2 +63 -14
- agentex/lib/cli/templates/temporal/README.md.j2 +24 -3
- agentex/lib/cli/templates/temporal/dev.ipynb.j2 +127 -0
- agentex/lib/core/adapters/streams/adapter_redis.py +4 -4
- agentex/lib/core/adapters/streams/port.py +1 -1
- agentex/lib/core/services/adk/streaming.py +2 -3
- agentex/lib/core/temporal/activities/__init__.py +2 -2
- agentex/lib/utils/dev_tools/__init__.py +9 -0
- agentex/lib/utils/dev_tools/async_messages.py +386 -0
- {agentex_sdk-0.2.0.dist-info → agentex_sdk-0.2.1.dist-info}/METADATA +1 -1
- {agentex_sdk-0.2.0.dist-info → agentex_sdk-0.2.1.dist-info}/RECORD +24 -19
- {agentex_sdk-0.2.0.dist-info → agentex_sdk-0.2.1.dist-info}/WHEEL +0 -0
- {agentex_sdk-0.2.0.dist-info → agentex_sdk-0.2.1.dist-info}/entry_points.txt +0 -0
- {agentex_sdk-0.2.0.dist-info → agentex_sdk-0.2.1.dist-info}/licenses/LICENSE +0 -0
agentex/_version.py
CHANGED
@@ -3,7 +3,7 @@ from datetime import timedelta
|
|
3
3
|
from temporalio.common import RetryPolicy
|
4
4
|
|
5
5
|
from agentex import AsyncAgentex
|
6
|
-
from agentex.lib.core.adapters.streams.adapter_redis import
|
6
|
+
from agentex.lib.core.adapters.streams.adapter_redis import RedisStreamRepository
|
7
7
|
from agentex.lib.core.services.adk.messages import MessagesService
|
8
8
|
from agentex.lib.core.services.adk.streaming import StreamingService
|
9
9
|
from agentex.lib.core.temporal.activities.activity_helpers import ActivityHelpers
|
@@ -38,7 +38,7 @@ class MessagesModule:
|
|
38
38
|
):
|
39
39
|
if messages_service is None:
|
40
40
|
agentex_client = AsyncAgentex()
|
41
|
-
stream_repository =
|
41
|
+
stream_repository = RedisStreamRepository()
|
42
42
|
streaming_service = StreamingService(
|
43
43
|
agentex_client=agentex_client,
|
44
44
|
stream_repository=stream_repository,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
from temporalio.common import RetryPolicy
|
2
2
|
|
3
3
|
from agentex import AsyncAgentex
|
4
|
-
from agentex.lib.core.adapters.streams.adapter_redis import
|
4
|
+
from agentex.lib.core.adapters.streams.adapter_redis import RedisStreamRepository
|
5
5
|
from agentex.lib.core.services.adk.streaming import (
|
6
6
|
StreamingService,
|
7
7
|
StreamingTaskMessageContext,
|
@@ -33,7 +33,7 @@ class StreamingModule:
|
|
33
33
|
a new service will be created with default parameters.
|
34
34
|
"""
|
35
35
|
if streaming_service is None:
|
36
|
-
stream_repository =
|
36
|
+
stream_repository = RedisStreamRepository()
|
37
37
|
agentex_client = AsyncAgentex()
|
38
38
|
self._streaming_service = StreamingService(
|
39
39
|
agentex_client=agentex_client,
|
@@ -5,7 +5,7 @@ from temporalio.common import RetryPolicy
|
|
5
5
|
|
6
6
|
from agentex import AsyncAgentex
|
7
7
|
from agentex.lib.core.adapters.llm.adapter_litellm import LiteLLMGateway
|
8
|
-
from agentex.lib.core.adapters.streams.adapter_redis import
|
8
|
+
from agentex.lib.core.adapters.streams.adapter_redis import RedisStreamRepository
|
9
9
|
from agentex.lib.core.services.adk.providers.litellm import LiteLLMService
|
10
10
|
from agentex.lib.core.services.adk.streaming import StreamingService
|
11
11
|
from agentex.lib.core.temporal.activities.activity_helpers import ActivityHelpers
|
@@ -40,7 +40,7 @@ class LiteLLMModule:
|
|
40
40
|
if litellm_service is None:
|
41
41
|
# Create default service
|
42
42
|
agentex_client = AsyncAgentex()
|
43
|
-
stream_repository =
|
43
|
+
stream_repository = RedisStreamRepository()
|
44
44
|
streaming_service = StreamingService(
|
45
45
|
agentex_client=agentex_client,
|
46
46
|
stream_repository=stream_repository,
|
@@ -10,7 +10,7 @@ from mcp import StdioServerParameters
|
|
10
10
|
from temporalio.common import RetryPolicy
|
11
11
|
|
12
12
|
from agentex import AsyncAgentex
|
13
|
-
from agentex.lib.core.adapters.streams.adapter_redis import
|
13
|
+
from agentex.lib.core.adapters.streams.adapter_redis import RedisStreamRepository
|
14
14
|
from agentex.lib.core.services.adk.providers.openai import OpenAIService
|
15
15
|
from agentex.lib.core.services.adk.streaming import StreamingService
|
16
16
|
from agentex.lib.core.temporal.activities.activity_helpers import ActivityHelpers
|
@@ -47,7 +47,7 @@ class OpenAIModule:
|
|
47
47
|
if openai_service is None:
|
48
48
|
# Create default service
|
49
49
|
agentex_client = AsyncAgentex()
|
50
|
-
stream_repository =
|
50
|
+
stream_repository = RedisStreamRepository()
|
51
51
|
streaming_service = StreamingService(
|
52
52
|
agentex_client=agentex_client,
|
53
53
|
stream_repository=stream_repository,
|
agentex/lib/cli/commands/init.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
from enum import Enum
|
2
2
|
from pathlib import Path
|
3
|
+
from typing import Any, Dict
|
3
4
|
|
4
5
|
import questionary
|
5
6
|
from jinja2 import Environment, FileSystemLoader
|
@@ -23,7 +24,7 @@ class TemplateType(str, Enum):
|
|
23
24
|
|
24
25
|
|
25
26
|
def render_template(
|
26
|
-
template_path: str, context:
|
27
|
+
template_path: str, context: Dict[str, Any], template_type: TemplateType
|
27
28
|
) -> str:
|
28
29
|
"""Render a template with the given context"""
|
29
30
|
env = Environment(loader=FileSystemLoader(TEMPLATES_DIR / template_type.value))
|
@@ -32,7 +33,7 @@ def render_template(
|
|
32
33
|
|
33
34
|
|
34
35
|
def create_project_structure(
|
35
|
-
path: Path, context:
|
36
|
+
path: Path, context: Dict[str, Any], template_type: TemplateType, use_uv: bool
|
36
37
|
):
|
37
38
|
"""Create the project structure from templates"""
|
38
39
|
# Create project directory
|
@@ -74,6 +75,9 @@ def create_project_structure(
|
|
74
75
|
root_templates["requirements.txt.j2"] = "requirements.txt"
|
75
76
|
root_templates["Dockerfile.j2"] = "Dockerfile"
|
76
77
|
|
78
|
+
# Add development notebook for agents
|
79
|
+
root_templates["dev.ipynb.j2"] = "dev.ipynb"
|
80
|
+
|
77
81
|
for template, output in root_templates.items():
|
78
82
|
output_path = project_dir / output
|
79
83
|
output_path.write_text(render_template(template, context, template_type))
|
@@ -81,7 +85,7 @@ def create_project_structure(
|
|
81
85
|
console.print(f"\n[green]✓[/green] Created project structure at: {project_dir}")
|
82
86
|
|
83
87
|
|
84
|
-
def get_project_context(answers:
|
88
|
+
def get_project_context(answers: Dict[str, Any], project_path: Path, manifest_root: Path) -> Dict[str, Any]:
|
85
89
|
"""Get the project context from user answers"""
|
86
90
|
# Use agent_directory_name as project_name
|
87
91
|
project_name = answers["agent_directory_name"].replace("-", "_")
|
@@ -112,7 +116,7 @@ def init():
|
|
112
116
|
)
|
113
117
|
|
114
118
|
# Use a Rich table for template descriptions
|
115
|
-
table = Table(show_header=True, header_style="bold
|
119
|
+
table = Table(show_header=True, header_style="bold blue")
|
116
120
|
table.add_column("Template", style="cyan", no_wrap=True)
|
117
121
|
table.add_column("Description", style="white")
|
118
122
|
table.add_row(
|
@@ -62,6 +62,7 @@ This file is essential for both local development and deployment of your agent.
|
|
62
62
|
│ └── acp.py # ACP server and event handlers
|
63
63
|
├── Dockerfile # Container definition
|
64
64
|
├── manifest.yaml # Deployment config
|
65
|
+
├── dev.ipynb # Development notebook for testing
|
65
66
|
{% if use_uv %}
|
66
67
|
└── pyproject.toml # Dependencies (uv)
|
67
68
|
{% else %}
|
@@ -76,7 +77,27 @@ This file is essential for both local development and deployment of your agent.
|
|
76
77
|
- Add your own tools and capabilities
|
77
78
|
- Implement custom state management
|
78
79
|
|
79
|
-
### 2.
|
80
|
+
### 2. Test Your Agent with the Development Notebook
|
81
|
+
Use the included `dev.ipynb` Jupyter notebook to test your agent interactively:
|
82
|
+
|
83
|
+
```bash
|
84
|
+
# Start Jupyter notebook (make sure you have jupyter installed)
|
85
|
+
jupyter notebook dev.ipynb
|
86
|
+
|
87
|
+
# Or use VS Code to open the notebook directly
|
88
|
+
code dev.ipynb
|
89
|
+
```
|
90
|
+
|
91
|
+
The notebook includes:
|
92
|
+
- **Setup**: Connect to your local AgentEx backend
|
93
|
+
- **Task creation**: Create a new task for the conversation
|
94
|
+
- **Event sending**: Send events to the agent and get responses
|
95
|
+
- **Async message subscription**: Subscribe to server-side events to receive agent responses
|
96
|
+
- **Rich message display**: Beautiful formatting with timestamps and author information
|
97
|
+
|
98
|
+
The notebook automatically uses your agent name (`{{ agent_name }}`) and demonstrates the agentic ACP workflow: create task → send event → subscribe to responses.
|
99
|
+
|
100
|
+
### 3. Manage Dependencies
|
80
101
|
|
81
102
|
{% if use_uv %}
|
82
103
|
You chose **uv** for package management. Here's how to work with dependencies:
|
@@ -115,7 +136,7 @@ pip install -r requirements.txt
|
|
115
136
|
- Wide compatibility
|
116
137
|
{% endif %}
|
117
138
|
|
118
|
-
###
|
139
|
+
### 4. Configure Credentials
|
119
140
|
Options:
|
120
141
|
1. Add any required credentials to your manifest.yaml via the `env` section
|
121
142
|
2. Export them in your shell: `export OPENAI_API_KEY=...`
|
@@ -0,0 +1,127 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": null,
|
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": null,
|
18
|
+
"id": "d1c309d6",
|
19
|
+
"metadata": {},
|
20
|
+
"outputs": [],
|
21
|
+
"source": [
|
22
|
+
"AGENT_NAME = \"{{ agent_name }}\""
|
23
|
+
]
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"cell_type": "code",
|
27
|
+
"execution_count": null,
|
28
|
+
"id": "9f6e6ef0",
|
29
|
+
"metadata": {},
|
30
|
+
"outputs": [],
|
31
|
+
"source": [
|
32
|
+
"# (REQUIRED) Create a new task. For Agentic agents, you must create a task for messages to be associated with.\n",
|
33
|
+
"\n",
|
34
|
+
"from typing import cast\n",
|
35
|
+
"import uuid\n",
|
36
|
+
"\n",
|
37
|
+
"from agentex.types import Task\n",
|
38
|
+
"\n",
|
39
|
+
"TASK_ID = str(uuid.uuid4())[:8]\n",
|
40
|
+
"\n",
|
41
|
+
"rpc_response = client.agents.rpc_by_name(\n",
|
42
|
+
" agent_name=AGENT_NAME,\n",
|
43
|
+
" method=\"task/create\",\n",
|
44
|
+
" params={\n",
|
45
|
+
" \"name\": f\"{TASK_ID}-task\",\n",
|
46
|
+
" \"params\": {}\n",
|
47
|
+
" }\n",
|
48
|
+
")\n",
|
49
|
+
"\n",
|
50
|
+
"task = cast(Task, rpc_response.result)\n",
|
51
|
+
"print(task)"
|
52
|
+
]
|
53
|
+
},
|
54
|
+
{
|
55
|
+
"cell_type": "code",
|
56
|
+
"execution_count": null,
|
57
|
+
"id": "b03b0d37",
|
58
|
+
"metadata": {},
|
59
|
+
"outputs": [],
|
60
|
+
"source": [
|
61
|
+
"# Test non streaming response\n",
|
62
|
+
"from typing import cast\n",
|
63
|
+
"from agentex.types import Event\n",
|
64
|
+
"\n",
|
65
|
+
"# The response is expected to be a list of TaskMessage objects, which is a union of the following types:\n",
|
66
|
+
"# - TextContent: A message with just text content \n",
|
67
|
+
"# - DataContent: A message with JSON-serializable data content\n",
|
68
|
+
"# - ToolRequestContent: A message with a tool request, which contains a JSON-serializable request to call a tool\n",
|
69
|
+
"# - ToolResponseContent: A message with a tool response, which contains response object from a tool call in its content\n",
|
70
|
+
"\n",
|
71
|
+
"# 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
|
+
"\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",
|
78
|
+
" \"task_id\": task.id,\n",
|
79
|
+
" }\n",
|
80
|
+
")\n",
|
81
|
+
"\n",
|
82
|
+
"event = cast(Event, rpc_response.result)\n",
|
83
|
+
"print(event)"
|
84
|
+
]
|
85
|
+
},
|
86
|
+
{
|
87
|
+
"cell_type": "code",
|
88
|
+
"execution_count": null,
|
89
|
+
"id": "a6927cc0",
|
90
|
+
"metadata": {},
|
91
|
+
"outputs": [],
|
92
|
+
"source": [
|
93
|
+
"from agentex.lib.utils.dev_tools import subscribe_to_async_task_messages\n",
|
94
|
+
"\n",
|
95
|
+
"task_messages = subscribe_to_async_task_messages(\n",
|
96
|
+
" client=client,\n",
|
97
|
+
" task=task, \n",
|
98
|
+
" only_after_timestamp=event.created_at, \n",
|
99
|
+
" print_messages=True,\n",
|
100
|
+
" rich_print=True,\n",
|
101
|
+
" timeout=5,\n",
|
102
|
+
")"
|
103
|
+
]
|
104
|
+
}
|
105
|
+
],
|
106
|
+
"metadata": {
|
107
|
+
"kernelspec": {
|
108
|
+
"display_name": ".venv",
|
109
|
+
"language": "python",
|
110
|
+
"name": "python3"
|
111
|
+
},
|
112
|
+
"language_info": {
|
113
|
+
"codemirror_mode": {
|
114
|
+
"name": "ipython",
|
115
|
+
"version": 3
|
116
|
+
},
|
117
|
+
"file_extension": ".py",
|
118
|
+
"mimetype": "text/x-python",
|
119
|
+
"name": "python",
|
120
|
+
"nbconvert_exporter": "python",
|
121
|
+
"pygments_lexer": "ipython3",
|
122
|
+
"version": "3.12.9"
|
123
|
+
}
|
124
|
+
},
|
125
|
+
"nbformat": 4,
|
126
|
+
"nbformat_minor": 5
|
127
|
+
}
|
@@ -60,6 +60,7 @@ This file is essential for both local development and deployment of your agent.
|
|
60
60
|
│ └── acp.py # ACP server and event handlers
|
61
61
|
├── Dockerfile # Container definition
|
62
62
|
├── manifest.yaml # Deployment config
|
63
|
+
├── dev.ipynb # Development notebook for testing
|
63
64
|
{% if use_uv %}
|
64
65
|
└── pyproject.toml # Dependencies (uv)
|
65
66
|
{% else %}
|
@@ -74,7 +75,26 @@ This file is essential for both local development and deployment of your agent.
|
|
74
75
|
- Add your own tools and capabilities
|
75
76
|
- Implement custom response generation
|
76
77
|
|
77
|
-
### 2.
|
78
|
+
### 2. Test Your Agent with the Development Notebook
|
79
|
+
Use the included `dev.ipynb` Jupyter notebook to test your agent interactively:
|
80
|
+
|
81
|
+
```bash
|
82
|
+
# Start Jupyter notebook (make sure you have jupyter installed)
|
83
|
+
jupyter notebook dev.ipynb
|
84
|
+
|
85
|
+
# Or use VS Code to open the notebook directly
|
86
|
+
code dev.ipynb
|
87
|
+
```
|
88
|
+
|
89
|
+
The notebook includes:
|
90
|
+
- **Setup**: Connect to your local AgentEx backend
|
91
|
+
- **Non-streaming tests**: Send messages and get complete responses
|
92
|
+
- **Streaming tests**: Test real-time streaming responses
|
93
|
+
- **Task management**: Optional task creation and management
|
94
|
+
|
95
|
+
The notebook automatically uses your agent name (`{{ agent_name }}`) and provides examples for both streaming and non-streaming message handling.
|
96
|
+
|
97
|
+
### 3. Manage Dependencies
|
78
98
|
|
79
99
|
{% if use_uv %}
|
80
100
|
You chose **uv** for package management. Here's how to work with dependencies:
|
@@ -113,7 +133,7 @@ pip install -r requirements.txt
|
|
113
133
|
- Wide compatibility
|
114
134
|
{% endif %}
|
115
135
|
|
116
|
-
###
|
136
|
+
### 4. Configure Credentials
|
117
137
|
Options:
|
118
138
|
1. Add any required credentials to your manifest.yaml via the `env` section
|
119
139
|
2. Export them in your shell: `export OPENAI_API_KEY=...`
|
@@ -0,0 +1,181 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": null,
|
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": null,
|
18
|
+
"id": "d1c309d6",
|
19
|
+
"metadata": {},
|
20
|
+
"outputs": [],
|
21
|
+
"source": [
|
22
|
+
"AGENT_NAME = \"{{ agent_name }}\""
|
23
|
+
]
|
24
|
+
},
|
25
|
+
{
|
26
|
+
"cell_type": "code",
|
27
|
+
"execution_count": null,
|
28
|
+
"id": "9f6e6ef0",
|
29
|
+
"metadata": {},
|
30
|
+
"outputs": [],
|
31
|
+
"source": [
|
32
|
+
"# # (Optional) Create a new task. If you don't create a new task, each message will be sent to a new task. The server will create the task for you.\n",
|
33
|
+
"\n",
|
34
|
+
"# import uuid\n",
|
35
|
+
"\n",
|
36
|
+
"# TASK_ID = str(uuid.uuid4())[:8]\n",
|
37
|
+
"\n",
|
38
|
+
"# rpc_response = client.agents.rpc_by_name(\n",
|
39
|
+
"# agent_name=AGENT_NAME,\n",
|
40
|
+
"# method=\"task/create\",\n",
|
41
|
+
"# params={\n",
|
42
|
+
"# \"name\": f\"{TASK_ID}-task\",\n",
|
43
|
+
"# \"params\": {}\n",
|
44
|
+
"# }\n",
|
45
|
+
"# )\n",
|
46
|
+
"\n",
|
47
|
+
"# task = rpc_response.result\n",
|
48
|
+
"# print(task)"
|
49
|
+
]
|
50
|
+
},
|
51
|
+
{
|
52
|
+
"cell_type": "code",
|
53
|
+
"execution_count": null,
|
54
|
+
"id": "b03b0d37",
|
55
|
+
"metadata": {},
|
56
|
+
"outputs": [],
|
57
|
+
"source": [
|
58
|
+
"# Test non streaming response\n",
|
59
|
+
"from typing import List, cast\n",
|
60
|
+
"from agentex.types import TaskMessage, TextContent\n",
|
61
|
+
"\n",
|
62
|
+
"# The response is expected to be a list of TaskMessage objects, which is a union of the following types:\n",
|
63
|
+
"# - TextContent: A message with just text content \n",
|
64
|
+
"# - DataContent: A message with JSON-serializable data content\n",
|
65
|
+
"# - ToolRequestContent: A message with a tool request, which contains a JSON-serializable request to call a tool\n",
|
66
|
+
"# - ToolResponseContent: A message with a tool response, which contains response object from a tool call in its content\n",
|
67
|
+
"\n",
|
68
|
+
"# 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",
|
69
|
+
"\n",
|
70
|
+
"rpc_response = client.agents.rpc_by_name(\n",
|
71
|
+
" agent_name=AGENT_NAME,\n",
|
72
|
+
" method=\"message/send\",\n",
|
73
|
+
" params={\n",
|
74
|
+
" \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello what can you do?\"},\n",
|
75
|
+
" \"stream\": False\n",
|
76
|
+
" }\n",
|
77
|
+
")\n",
|
78
|
+
"\n",
|
79
|
+
"# # Extract and print just the text content from the response\n",
|
80
|
+
"# # The response is expected to be a dict with a \"result\" key containing a list of message dicts\n",
|
81
|
+
"if rpc_response and rpc_response.result:\n",
|
82
|
+
"\n",
|
83
|
+
" # We know that the result of the message/send when stream is set to False will be a list of TaskMessage objects\n",
|
84
|
+
" task_message_list = cast(List[TaskMessage], rpc_response.result)\n",
|
85
|
+
" for task_message in rpc_response.result:\n",
|
86
|
+
" if isinstance(task_message, TaskMessage):\n",
|
87
|
+
" content = task_message.content\n",
|
88
|
+
" if isinstance(content, TextContent):\n",
|
89
|
+
" text = content.content\n",
|
90
|
+
" print(text)\n",
|
91
|
+
" else:\n",
|
92
|
+
" print(f\"Found non-text {type(task_message)} object in response.\")\n"
|
93
|
+
]
|
94
|
+
},
|
95
|
+
{
|
96
|
+
"cell_type": "code",
|
97
|
+
"execution_count": null,
|
98
|
+
"id": "79688331",
|
99
|
+
"metadata": {},
|
100
|
+
"outputs": [],
|
101
|
+
"source": [
|
102
|
+
"# Test streaming response\n",
|
103
|
+
"import json\n",
|
104
|
+
"from agentex.types import AgentRpcResponse\n",
|
105
|
+
"from agentex.types.agent_rpc_result import StreamTaskMessageDelta, StreamTaskMessageFull\n",
|
106
|
+
"from agentex.types.text_delta import TextDelta\n",
|
107
|
+
"from agentex.types.task_message_update import TaskMessageUpdate\n",
|
108
|
+
"\n",
|
109
|
+
"\n",
|
110
|
+
"# The result object of message/send will be a TaskMessageUpdate which is a union of the following types:\n",
|
111
|
+
"# - StreamTaskMessageStart: \n",
|
112
|
+
"# - An indicator that a streaming message was started, doesn't contain any useful content\n",
|
113
|
+
"# - StreamTaskMessageDelta: \n",
|
114
|
+
"# - A delta of a streaming message, contains the text delta to aggregate\n",
|
115
|
+
"# - StreamTaskMessageDone: \n",
|
116
|
+
"# - An indicator that a streaming message was done, doesn't contain any useful content\n",
|
117
|
+
"# - StreamTaskMessageFull: \n",
|
118
|
+
"# - A non-streaming message, there is nothing to aggregate, since this contains the full message, not deltas\n",
|
119
|
+
"\n",
|
120
|
+
"# Whenn processing StreamTaskMessageDelta, if you are expecting more than TextDeltas, such as DataDelta, ToolRequestDelta, or ToolResponseDelta, you can process them as well\n",
|
121
|
+
"# Whenn processing StreamTaskMessageFull, if you are expecting more than TextContent, such as DataContent, ToolRequestContent, or ToolResponseContent, you can process them as well\n",
|
122
|
+
"\n",
|
123
|
+
"with client.agents.with_streaming_response.rpc_by_name(\n",
|
124
|
+
" agent_name=AGENT_NAME,\n",
|
125
|
+
" method=\"message/send\",\n",
|
126
|
+
" params={\n",
|
127
|
+
" \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello what can you do?\"},\n",
|
128
|
+
" \"stream\": True\n",
|
129
|
+
" }\n",
|
130
|
+
") as response:\n",
|
131
|
+
" for agent_rpc_response_str in response.iter_text():\n",
|
132
|
+
" chunk_rpc_response = AgentRpcResponse.model_validate(json.loads(agent_rpc_response_str))\n",
|
133
|
+
" # We know that the result of the message/send when stream is set to True will be a TaskMessageUpdate\n",
|
134
|
+
" task_message_update = cast(TaskMessageUpdate, chunk_rpc_response.result)\n",
|
135
|
+
"\n",
|
136
|
+
" # Print oly the text deltas as they arrive or any full messages\n",
|
137
|
+
" if isinstance(task_message_update, StreamTaskMessageDelta):\n",
|
138
|
+
" delta = task_message_update.delta\n",
|
139
|
+
" if isinstance(delta, TextDelta):\n",
|
140
|
+
" print(delta.text_delta, end=\"\", flush=True)\n",
|
141
|
+
" else:\n",
|
142
|
+
" print(f\"Found non-text {type(task_message)} object in streaming message.\")\n",
|
143
|
+
" elif isinstance(task_message_update, StreamTaskMessageFull):\n",
|
144
|
+
" content = task_message_update.content\n",
|
145
|
+
" if isinstance(content, TextContent):\n",
|
146
|
+
" print(content.content)\n",
|
147
|
+
" else:\n",
|
148
|
+
" print(f\"Found non-text {type(task_message)} object in full message.\")\n"
|
149
|
+
]
|
150
|
+
},
|
151
|
+
{
|
152
|
+
"cell_type": "code",
|
153
|
+
"execution_count": null,
|
154
|
+
"id": "4ffb663c",
|
155
|
+
"metadata": {},
|
156
|
+
"outputs": [],
|
157
|
+
"source": []
|
158
|
+
}
|
159
|
+
],
|
160
|
+
"metadata": {
|
161
|
+
"kernelspec": {
|
162
|
+
"display_name": ".venv",
|
163
|
+
"language": "python",
|
164
|
+
"name": "python3"
|
165
|
+
},
|
166
|
+
"language_info": {
|
167
|
+
"codemirror_mode": {
|
168
|
+
"name": "ipython",
|
169
|
+
"version": 3
|
170
|
+
},
|
171
|
+
"file_extension": ".py",
|
172
|
+
"mimetype": "text/x-python",
|
173
|
+
"name": "python",
|
174
|
+
"nbconvert_exporter": "python",
|
175
|
+
"pygments_lexer": "ipython3",
|
176
|
+
"version": "3.12.9"
|
177
|
+
}
|
178
|
+
},
|
179
|
+
"nbformat": 4,
|
180
|
+
"nbformat_minor": 5
|
181
|
+
}
|
@@ -1,26 +1,75 @@
|
|
1
|
-
|
1
|
+
import json
|
2
|
+
from agentex.lib import adk
|
2
3
|
from agentex.lib.sdk.fastacp.fastacp import FastACP
|
3
|
-
from agentex.lib.types.
|
4
|
+
from agentex.lib.types.fastacp import AgenticACPConfig
|
5
|
+
from agentex.lib.types.acp import CancelTaskParams, CreateTaskParams, SendEventParams
|
4
6
|
|
5
|
-
from agentex.lib.types.task_message_updates import TaskMessageUpdate
|
6
|
-
from agentex.types.task_message_content import TaskMessageContent
|
7
7
|
from agentex.types.text_content import TextContent
|
8
8
|
from agentex.lib.utils.logging import make_logger
|
9
9
|
|
10
10
|
logger = make_logger(__name__)
|
11
11
|
|
12
12
|
|
13
|
-
# Create an ACP server
|
13
|
+
# Create an ACP server with base configuration
|
14
|
+
# This sets up the core server that will handle task creation, events, and cancellation
|
14
15
|
acp = FastACP.create(
|
15
|
-
acp_type="
|
16
|
+
acp_type="agentic",
|
17
|
+
config=AgenticACPConfig(
|
18
|
+
type="base",
|
19
|
+
),
|
16
20
|
)
|
17
21
|
|
18
|
-
@acp.
|
19
|
-
async def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
@acp.on_task_create
|
23
|
+
async def handle_task_create(params: CreateTaskParams):
|
24
|
+
# This handler is called first whenever a new task is created.
|
25
|
+
# It's a good place to initialize any state or resources needed for the task.
|
26
|
+
|
27
|
+
#########################################################
|
28
|
+
# 1. (👋) Do task initialization here.
|
29
|
+
#########################################################
|
30
|
+
|
31
|
+
# Acknowledge that the task has been created.
|
32
|
+
await adk.messages.create(
|
33
|
+
task_id=params.task.id,
|
34
|
+
content=TextContent(
|
35
|
+
author="agent",
|
36
|
+
content=f"Hello! I've received your task. Normally you can do some state initialization here, or just pass and do nothing until you get your first event. For now I'm just acknowledging that I've received a task with the following params:\n\n{json.dumps(params.params, indent=2)}.\n\nYou should only see this message once, when the task is created. All subsequent events will be handled by the `on_task_event_send` handler.",
|
37
|
+
),
|
26
38
|
)
|
39
|
+
|
40
|
+
@acp.on_task_event_send
|
41
|
+
async def handle_event_send(params: SendEventParams):
|
42
|
+
# This handler is called whenever a new event (like a message) is sent to the task
|
43
|
+
|
44
|
+
#########################################################
|
45
|
+
# 2. (👋) Echo back the client's message to show it in the UI.
|
46
|
+
#########################################################
|
47
|
+
|
48
|
+
# This is not done by default so the agent developer has full control over what is shown to the user.
|
49
|
+
if params.event.content:
|
50
|
+
await adk.messages.create(task_id=params.task.id, content=params.event.content)
|
51
|
+
|
52
|
+
#########################################################
|
53
|
+
# 3. (👋) Send a simple response message.
|
54
|
+
#########################################################
|
55
|
+
|
56
|
+
# In future tutorials, this is where we'll add more sophisticated response logic.
|
57
|
+
await adk.messages.create(
|
58
|
+
task_id=params.task.id,
|
59
|
+
content=TextContent(
|
60
|
+
author="agent",
|
61
|
+
content=f"Hello! I've received your message. I can't respond right now, but in future tutorials we'll see how you can get me to intelligently respond to your message.",
|
62
|
+
),
|
63
|
+
)
|
64
|
+
|
65
|
+
@acp.on_task_cancel
|
66
|
+
async def handle_task_cancel(params: CancelTaskParams):
|
67
|
+
# This handler is called when a task is cancelled.
|
68
|
+
# It's useful for cleaning up any resources or state associated with the task.
|
69
|
+
|
70
|
+
#########################################################
|
71
|
+
# 4. (👋) Do task cleanup here.
|
72
|
+
#########################################################
|
73
|
+
|
74
|
+
# This is mostly for durable workflows that are cancellable like Temporal, but we will leave it here for demonstration purposes.
|
75
|
+
logger.info(f"Hello! I've received task cancel for task {params.task.id}: {params.task}. This isn't necessary for this example, but it's good to know that it's available.")
|
@@ -68,6 +68,7 @@ This file is essential for both local development and deployment of your agent.
|
|
68
68
|
│ └── run_worker.py # Temporal worker setup
|
69
69
|
├── Dockerfile # Container definition
|
70
70
|
├── manifest.yaml # Deployment config
|
71
|
+
├── dev.ipynb # Development notebook for testing
|
71
72
|
{% if use_uv %}
|
72
73
|
└── pyproject.toml # Dependencies (uv)
|
73
74
|
{% else %}
|
@@ -82,12 +83,32 @@ This file is essential for both local development and deployment of your agent.
|
|
82
83
|
- Add your own tools and capabilities
|
83
84
|
- Implement custom state management
|
84
85
|
|
85
|
-
### 2.
|
86
|
+
### 2. Test Your Agent with the Development Notebook
|
87
|
+
Use the included `dev.ipynb` Jupyter notebook to test your agent interactively:
|
88
|
+
|
89
|
+
```bash
|
90
|
+
# Start Jupyter notebook (make sure you have jupyter installed)
|
91
|
+
jupyter notebook dev.ipynb
|
92
|
+
|
93
|
+
# Or use VS Code to open the notebook directly
|
94
|
+
code dev.ipynb
|
95
|
+
```
|
96
|
+
|
97
|
+
The notebook includes:
|
98
|
+
- **Setup**: Connect to your local AgentEx backend
|
99
|
+
- **Task creation**: Create a new task for the conversation
|
100
|
+
- **Event sending**: Send events to the agent and get responses
|
101
|
+
- **Async message subscription**: Subscribe to server-side events to receive agent responses
|
102
|
+
- **Rich message display**: Beautiful formatting with timestamps and author information
|
103
|
+
|
104
|
+
The notebook automatically uses your agent name (`{{ agent_name }}`) and demonstrates the agentic ACP workflow: create task → send event → subscribe to responses.
|
105
|
+
|
106
|
+
### 3. Develop Temporal Workflows
|
86
107
|
- Edit `workflow.py` to define your agent's async workflow logic
|
87
108
|
- Modify `activities.py` to add custom activities
|
88
109
|
- Use `run_worker.py` to configure the Temporal worker
|
89
110
|
|
90
|
-
###
|
111
|
+
### 4. Manage Dependencies
|
91
112
|
|
92
113
|
{% if use_uv %}
|
93
114
|
You chose **uv** for package management. Here's how to work with dependencies:
|
@@ -135,7 +156,7 @@ pip install -r requirements.txt
|
|
135
156
|
- Wide compatibility
|
136
157
|
{% endif %}
|
137
158
|
|
138
|
-
###
|
159
|
+
### 5. Configure Credentials
|
139
160
|
- Add any required credentials to your manifest.yaml
|
140
161
|
- For local development, create a `.env` file in the project directory
|
141
162
|
- Use `load_dotenv()` only in development mode:
|