A sample agent (CurrencyAgent) utilizing the OpenAI Agents SDK and served via the A2A protocol.
This is code is not meant to be used in production. Furthermore, at the time of making this example the A2A protocol spec is being actively developed.
- Python 3.13
- uv
-
Clone the repository:
git clone https://github.com/darkhaniop/a2a-openai-agent-sample.git
-
Navigate to
a2a-openai-agent-sample
and install dependencies:cd a2a-openai-agent-sample uv sync
uv sync
will install theopenai-agents
with its dependencies and thea2a-samples
package from GitHub. -
Make sure the environment variable
OPENAI_API_KEY
is set, or alternatively, create a.env
file with the key:OPENAI_API_KEY="your-OPENAI-key"
-
Start the server (by defult it will listen on
localhost:10101
):uv run python -m a2a_openai_agent_sample
or specify a custom port:
uv run python -m a2a_openai_agent_sample --port 23232
-
In another terminal, run one of the sample clients according to the instructions in
a2a-samples
(see google/A2A:samples/python/hosts/). For example, navigate to the directory with your local copy ofA2A
and launch the CLI client:cd A2A cd samples/python/hosts/cli uv run . --agent http://localhost:10101
- User: what is the USD to JPY rate?
- Agent: The current exchange rate from USD to JPY is 142.84.
- User: What was the exchange rate for the same pair on March 1, 2025?
- Agent: The exchange rate from USD to JPY on March 1, 2025, was 150.76.
- User: How are the markets doing today?
- Agent: I can only assist with currency-related queries and cannot provide information on market conditions.
- User: What was the exchange rate from USD to British pounds on March 1, 2021?
- Agent: The exchange rate from USD to British pounds on March 1, 2021, was 0.71814 GBP for 1 USD.
- User: What was the conversion rate the other way around?
- Agent: The exchange rate from British pounds to USD on March 1, 2021, was 1.3925 USD for 1 GBP.
The code in this repository is meant to reproduce the functionality of the langchain
agent from the a2a-samples
project and is largely derived from scripts in that repository. It uses task_manager.py
and __main__.py
(from agents/langchain
) with only adjusted import statements. A copy of the original LICENSE file from a2a-samples
is in original-a2a-samples-LICENSE.txt.