-
Notifications
You must be signed in to change notification settings - Fork 0
custom activity example #59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
charlotte-zhuang
wants to merge
4
commits into
main
Choose a base branch
from
c/examples/custom_activity/0
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
examples/tutorials/10_agentic/10_temporal/011_custom_agent_chat/.dockerignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| # Python | ||
| __pycache__/ | ||
| *.py[cod] | ||
| *$py.class | ||
| *.so | ||
| .Python | ||
| build/ | ||
| develop-eggs/ | ||
| dist/ | ||
| downloads/ | ||
| eggs/ | ||
| .eggs/ | ||
| lib/ | ||
| lib64/ | ||
| parts/ | ||
| sdist/ | ||
| var/ | ||
| wheels/ | ||
| *.egg-info/ | ||
| .installed.cfg | ||
| *.egg | ||
|
|
||
| # Environments | ||
| .env** | ||
| .venv | ||
| env/ | ||
| venv/ | ||
| ENV/ | ||
| env.bak/ | ||
| venv.bak/ | ||
|
|
||
| # IDE | ||
| .idea/ | ||
| .vscode/ | ||
| *.swp | ||
| *.swo | ||
|
|
||
| # Git | ||
| .git | ||
| .gitignore | ||
|
|
||
| # Misc | ||
| .DS_Store |
48 changes: 48 additions & 0 deletions
48
examples/tutorials/10_agentic/10_temporal/011_custom_agent_chat/Dockerfile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # syntax=docker/dockerfile:1.3 | ||
| FROM python:3.12-slim | ||
| COPY --from=ghcr.io/astral-sh/uv:0.6.4 /uv /uvx /bin/ | ||
|
|
||
| # Install system dependencies | ||
| RUN apt-get update && apt-get install -y \ | ||
| htop \ | ||
| vim \ | ||
| curl \ | ||
| tar \ | ||
| python3-dev \ | ||
| postgresql-client \ | ||
| build-essential \ | ||
| libpq-dev \ | ||
| gcc \ | ||
| cmake \ | ||
| netcat-openbsd \ | ||
| && apt-get clean \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Install tctl (Temporal CLI) | ||
| RUN curl -L https://github.com/temporalio/tctl/releases/download/v1.18.1/tctl_1.18.1_linux_arm64.tar.gz -o /tmp/tctl.tar.gz && \ | ||
| tar -xzf /tmp/tctl.tar.gz -C /usr/local/bin && \ | ||
| chmod +x /usr/local/bin/tctl && \ | ||
| rm /tmp/tctl.tar.gz | ||
|
|
||
| RUN uv pip install --system --upgrade pip setuptools wheel | ||
|
|
||
| ENV UV_HTTP_TIMEOUT=1000 | ||
|
|
||
| # Copy just the requirements file to optimize caching | ||
| COPY 000_hello_acp/requirements.txt /app/requirements.txt | ||
|
|
||
| WORKDIR /app/ | ||
|
|
||
| # Install the required Python packages | ||
| RUN uv pip install --system -r requirements.txt | ||
|
|
||
| # Copy the project code | ||
| COPY 000_hello_acp/project /app/project | ||
charlotte-zhuang marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| WORKDIR /app/project | ||
|
|
||
| # Run the ACP server using uvicorn | ||
| CMD ["uvicorn", "acp:acp", "--host", "0.0.0.0", "--port", "8000"] | ||
|
|
||
| # When we deploy the worker, we will replace the CMD with the following | ||
| # CMD ["python", "-m", "run_worker"] | ||
8 changes: 8 additions & 0 deletions
8
examples/tutorials/10_agentic/10_temporal/011_custom_agent_chat/Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| install-dev: | ||
| uv sync --group dev | ||
|
|
||
| dev: install-dev | ||
| uv run --env-file=.env agentex agents run --manifest manifest.yaml | ||
|
|
||
| typecheck: install-dev | ||
| uv run mypy project --strict |
3 changes: 3 additions & 0 deletions
3
examples/tutorials/10_agentic/10_temporal/011_custom_agent_chat/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # [Agentic] Agentic Chat with a Custom Temporal Activity | ||
|
|
||
| This tutorial demonstrates how to implement a custom temporal activity with agentic ACP. |
126 changes: 126 additions & 0 deletions
126
examples/tutorials/10_agentic/10_temporal/011_custom_agent_chat/dev.ipynb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,126 @@ | ||
| { | ||
| "cells": [ | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "0", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "from agentex import Agentex\n", | ||
| "\n", | ||
| "client = Agentex(base_url=\"http://localhost:5003\")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "1", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "AGENT_NAME = \"at011-custom-agent-chat\"" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "2", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# (REQUIRED) Create a new task. For Agentic agents, you must create a task for messages to be associated with.\n", | ||
| "import uuid\n", | ||
| "\n", | ||
| "rpc_response = client.agents.create_task(\n", | ||
| " agent_name=AGENT_NAME,\n", | ||
| " params={\n", | ||
| " \"name\": f\"{str(uuid.uuid4())[:8]}-task\",\n", | ||
| " \"params\": {}\n", | ||
| " }\n", | ||
| ")\n", | ||
| "\n", | ||
| "task = rpc_response.result\n", | ||
| "task" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "3", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Send an event to the agent\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", | ||
| "\n", | ||
| "rpc_response = client.agents.send_event(\n", | ||
| " agent_name=AGENT_NAME,\n", | ||
| " params={\n", | ||
| " \"content\": {\"type\": \"text\", \"author\": \"user\", \"content\": \"Hello what can you do?\"},\n", | ||
| " \"task_id\": task.id,\n", | ||
| " }\n", | ||
| ")\n", | ||
| "\n", | ||
| "event = rpc_response.result\n", | ||
| "event" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "4", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "# Subscribe to the async task messages produced by the agent\n", | ||
| "from agentex.lib.utils.dev_tools import subscribe_to_async_task_messages\n", | ||
| "\n", | ||
| "task_messages = subscribe_to_async_task_messages(\n", | ||
| " client=client,\n", | ||
| " task=task, \n", | ||
| " only_after_timestamp=event.created_at, \n", | ||
| " print_messages=True,\n", | ||
| " rich_print=True,\n", | ||
| " timeout=5,\n", | ||
| ")" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "5", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [] | ||
| } | ||
| ], | ||
| "metadata": { | ||
| "kernelspec": { | ||
| "display_name": "at001-custom-temporal-activity", | ||
| "language": "python", | ||
| "name": "python3" | ||
| }, | ||
| "language_info": { | ||
| "codemirror_mode": { | ||
| "name": "ipython", | ||
| "version": 3 | ||
| }, | ||
| "file_extension": ".py", | ||
| "mimetype": "text/x-python", | ||
| "name": "python", | ||
| "nbconvert_exporter": "python", | ||
| "pygments_lexer": "ipython3", | ||
| "version": "3.13.5" | ||
| } | ||
| }, | ||
| "nbformat": 4, | ||
| "nbformat_minor": 5 | ||
| } |
3 changes: 3 additions & 0 deletions
3
examples/tutorials/10_agentic/10_temporal/011_custom_agent_chat/example.env
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| OPENAI_API_KEY=123 | ||
| SCALE_GP_API_KEY=abc | ||
| SCALE_GP_ACCOUNT_ID=456 |
135 changes: 135 additions & 0 deletions
135
examples/tutorials/10_agentic/10_temporal/011_custom_agent_chat/manifest.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,135 @@ | ||
| # Agent Manifest Configuration | ||
| # --------------------------- | ||
| # This file defines how your agent should be built and deployed. | ||
|
|
||
| # Build Configuration | ||
| # ------------------ | ||
| # The build config defines what gets packaged into your agent's Docker image. | ||
| # This same configuration is used whether building locally or remotely. | ||
| # | ||
| # When building: | ||
| # 1. All files from include_paths are collected into a build context | ||
| # 2. The context is filtered by dockerignore rules | ||
| # 3. The Dockerfile uses this context to build your agent's image | ||
| # 4. The image is pushed to a registry and used to run your agent | ||
| build: | ||
| context: | ||
| # Root directory for the build context | ||
| root: ../ # Keep this as the default root | ||
|
|
||
| # Paths to include in the Docker build context | ||
| # Must include: | ||
| # - Your agent's directory (your custom agent code) | ||
| # These paths are collected and sent to the Docker daemon for building | ||
| include_paths: | ||
| - 011_custom_agent_chat | ||
|
|
||
| # Path to your agent's Dockerfile | ||
| # This defines how your agent's image is built from the context | ||
| # Relative to the root directory | ||
| dockerfile: 011_custom_agent_chat/Dockerfile | ||
|
|
||
| # Path to your agent's .dockerignore | ||
| # Filters unnecessary files from the build context | ||
| # Helps keep build context small and builds fast | ||
| dockerignore: 011_custom_agent_chat/.dockerignore | ||
|
|
||
| # Local Development Configuration | ||
| # ----------------------------- | ||
| # Only used when running the agent locally | ||
| local_development: | ||
| agent: | ||
| port: 8000 # Port where your local ACP server is running | ||
| host_address: host.docker.internal # Host address for Docker networking (host.docker.internal for Docker, localhost for direct) | ||
|
|
||
| # File paths for local development (relative to this manifest.yaml) | ||
| paths: | ||
| # Path to ACP server file | ||
| # Examples: | ||
| # project/acp.py (standard) | ||
| # src/server.py (custom structure) | ||
| # ../shared/acp.py (shared across projects) | ||
| # /absolute/path/acp.py (absolute path) | ||
| acp: project/acp.py | ||
|
|
||
| # Path to temporal worker file | ||
| # Examples: | ||
| # project/run_worker.py (standard) | ||
| # workers/temporal.py (custom structure) | ||
| # ../shared/worker.py (shared across projects) | ||
| worker: project/run_worker.py | ||
|
|
||
| # Agent Configuration | ||
| # ----------------- | ||
| agent: | ||
| # Type of agent - either sync or agentic | ||
| acp_type: agentic | ||
|
|
||
| # Unique name for your agent | ||
| # Used for task routing and monitoring | ||
| name: at011-custom-agent-chat | ||
|
|
||
| # Description of what your agent does | ||
| # Helps with documentation and discovery | ||
| description: An AgentEx agent that streams chat using a custom Temporal activity | ||
|
|
||
| # Temporal workflow configuration | ||
| # This enables your agent to run as a Temporal workflow for long-running tasks | ||
| temporal: | ||
| enabled: true | ||
| workflows: | ||
| # Name of the workflow class | ||
| # Must match the @workflow.defn name in your workflow.py | ||
| - name: at011-custom-agent-chat | ||
|
|
||
| # Queue name for task distribution | ||
| # Used by Temporal to route tasks to your agent | ||
| # Convention: <agent_name>_task_queue | ||
| queue_name: 011_custom_agent_chat_queue | ||
|
|
||
| # Optional: Credentials mapping | ||
| # Maps Kubernetes secrets to environment variables | ||
| # Common credentials include: | ||
| # credentials: | ||
| # - env_var_name: OPENAI_API_KEY | ||
| # secret_name: openai-api-key | ||
| # secret_key: api-key | ||
|
|
||
| # Optional: Set Environment variables for running your agent locally as well | ||
| # as for deployment later on | ||
| # env: | ||
| # - name: OPENAI_BASE_URL | ||
| # value: "https://api.openai.com/v1" | ||
| # - name: ACCOUNT_ID | ||
| # value: "your_account_id_here" | ||
|
|
||
| # Deployment Configuration | ||
| # ----------------------- | ||
| # Configuration for deploying your agent to Kubernetes clusters | ||
| deployment: | ||
| # Container image configuration | ||
| image: | ||
| repository: "" # Update with your container registry | ||
| tag: "latest" # Default tag, should be versioned in production | ||
|
|
||
| imagePullSecrets: | ||
| - name: my-registry-secret # Update with your image pull secret name | ||
|
|
||
| # Global deployment settings that apply to all clusters | ||
| # These can be overridden using --override-file with custom configuration files | ||
| global: | ||
| agent: | ||
| name: "at011-custom-agent-chat" | ||
| description: "An AgentEx agent that streams chat using a custom Temporal activity" | ||
|
|
||
| # Default replica count | ||
| replicaCount: 1 | ||
|
|
||
| # Default resource requirements | ||
| resources: | ||
| requests: | ||
| cpu: "500m" | ||
| memory: "1Gi" | ||
| limits: | ||
| cpu: "1000m" | ||
| memory: "2Gi" |
Empty file.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.