Agent development using Java
Prerequisites
- Python environment
- uv 0.7.4+
- Python 3.13+
- Install
tuna-fusionin Kubernetes cluster - Understanding about A2A protocol
- Understanding about how to develop with a2a-python SDK
- Introduction of a2a-python
- AgentExecutor
- Code sample to export LangCloud agent using
AgentExecutor: a2a-samples/samples/python/agents/langgraph/app /agent_executor.py
A tour of hello-world agent
To demonstrate the basic workflow of deploying an agent, we will create a simple agent that returns a greeting message.
Create project folder
First, we initialize an empty folder and initialize as a Git repository.
Info
You can check out the complete code sample from samples repository directly.
Write an AgentExecutor
As we are going to use AgentExecutor class, we have to declare a2a-sdk as only dependency.
And create the source file of HelloWorldAgentExecutor.
- Use official
a2a-pythonSDK to create an agent executor. - Reply simple "hello world" message to the client once a client connects and send an arbitrary message.
- Explicitly use timestamps without timezone info so that Java client can correctly parse them. This is a known issue.
Create AgentEnvirontment resource
Info
Let's make some assumptions about how tuna-fusion is installed:
tuna-fusionis installed indefaultnamespace, so you don't need to specify namespace in themetadata.namespacefield of resources andkubectlcommands in later sections.- You can access
tuna-fusion-gitops-serverandtuna-fusion-exeuctorusing Kuberentes Service domains on port 80, specificallytuna-fusion-gitops-server.default.svc.cluster.localandtuna-fusion-executor.default.svc.cluster.local.
If you have tuna-fusion with default Helm chart values, you don't need to touch anything to make example code to work.
If namespace or any other chart value is changed, you need to update the code samples accordingly.
AgentEnvironment should be created before actual agent deployment. You can create one AgentEnvironment resource for a group of logically related agent instances which often share some common configurations.
| agent-env-1.yaml | |
|---|---|
apiVersionfortuna-fusionCRDs- Name of the
AgentEnvironment: It should be unique in the namespace and it will be used inAgentDeploymentlater. PodPoolis used as provision driver and detailed properties forPodPoolcan be configured inpodPoolSpecfield. See CRD Reference for more details
And let's apply it to the cluster:
Create AgentDeployment resource
AgentDeployment resource should be created for each standalone agent project.
- Notice here this resource is kind of
AgentDeployment - Name of
AgentDeploymentis treated as the name of the agent. - Yes. It's the agent card definition of your agent.
- It should be the name of a properly created
AgentEnvironment. - The branch name to watch. If not specified,
mainwill be used. - The A2A runtime configurations. Default in-memory implementations of TaskStore and QueueManager can be used as test purposes. It's advised to use external storage to support sessions in distributed deployments. See CRDs Reference for move advanced configurations.
- The import path
AgentExecutorclass. In this case, it'sapp.HelloWorldAgentExecutorasHelloWorldAgentExecutorinapp.pyPython file.
Let's apply it to the cluster:
You can see the details of AgentDeployment you just created.
Commit the code changes
There are two ways to update agent deployments:
- Manually create a
PodFunctionBuild. - Update code changes through
tuna-fusion-gitops-server.
Both solutions will trigger build pipeline to run automatically. As creating PodFunctionBuild for each update is tedious, we recommend using tuna-fusion-gitops-server to update code changes.
Using virtual Git repository server
To push updates using git client, we have to add a git remote first:
git remote add test-deploy-1 http://tuna-fusion-gitops-server.default.svc.cluster.local/repositories/namespacs/default/agents/test-deploy-1.git
Warning
If you are using a clone of code sample repositoriy which contains a lot of sub-projects of agent samples. You can add remote with sub-project path, like this:
git remote add test-deploy-1 http://tuna-fusion-gitops-server.default.svc.cluster.local/repositories/namespacs/default/agents/test-deploy-1/hello_world.git
Notice the hello_world part before .git above.
Warning
tuna-fusion-gitops-server won't persist the code data you commit. In fact, those updates will be discarded right after a git push is finished.
Use virtual repositroies solely for CI pipelines not for traiditonal source code management.
After a remote has been set, you can commence your first push to the virtual repository:
During the push, tuna-fusion will:
- Fetch updated git objects and create a snapshot archive of latest commit.
- Trigger a single execution of build pipeline.
- Livestream the build logs to the user.
Alternative way: Create PodFunctionBuild manually
Example resource manifest:
PodFunctionBuildis a resource that triggers build process.- Resource names should be unique across all builds.
- Reference the
PodFunctionwe created earlier. - Source archive is provided via HTTP URL. It should be accessible for
tuna-fusionto download. - SHA256 checksum for this URL. Build will fail if checksum failed.
Check status of test-deploy-1
After the push is processed, you can check the status of AgentDeployment by running:
Here ad is abbreviation of AgentDeployment, and test-deploy-1 is the name of the AgentDeployment resource. In the CURRENTBUILD column you should see latest build in status of success.
Before continue to next part, let's write down the link in URL column of deployed agent, which is the base URL for A2A Client.
Visiting your first agent
To interact with test-deploy-1 agent, you can use a2a-inspector utility. Or just write a simple python script to send messages.
In the following code, we demonstrate how to access test-deploy-1 using a2a-python SDK.
- Configure logging to show INFO level messages
- The URL we take from
test-deploy-1's status fields in last step - Initialize a client with the base URL of
test-deploy-1 - Prepare a streaming request
- Iterating chunk data of the streaming response using
async for loop
Summary
In this tutorial, we have completed the round trip of deploying an application using tuna-fusion. Although the hello-world agent is a simple one, it demonstrates the basic usage of tuna-fusion. Of course, you can discover more complicated samples in tuna-fusion-agent-samples or a2aproject/a2a-samples.