AgentVault LangChain Integration Example¶
This directory contains a basic example demonstrating how to integrate an AgentVault A2A compliant agent as a tool within the LangChain framework.
Components¶
requirements.txt: Defines the necessary Python dependencies (langchain-core,agentvault,httpx).a2a_tool.py: Contains theA2AAgentToolclass, which inherits from LangChain'sBaseTool. This tool handles the interaction with a remote A2A agent using theagentvaultclient library.example_usage.py: A simple script showing how to instantiate and invoke theA2AAgentTool.
Setup¶
-
Install Dependencies: Navigate to this directory (
Note: This assumes your virtual environment is activated and you are in the correct directory. Theexamples/langchain_integration) in your terminal and install the requirements. This includes installing the localagentvaultlibrary in editable mode.-e ../../agentvault_libraryline installs the library from your local source tree. -
Configure Agent Reference: Open
example_usage.pyand modify theEXAMPLE_AGENT_REFvariable to point to a valid agent:- Agent ID: If using an ID from a running AgentVault Registry (e.g.,
test-org/my-agent), ensure theAGENTVAULT_REGISTRY_URLenvironment variable is set correctly or modify the default ina2a_tool.py. - Agent URL: Provide the direct URL to the agent's
agent-card.json(e.g.,http://localhost:8001/agent-card.json). - Local File: Provide the path to a local
agent-card.jsonfile (e.g.,./path/to/your/agent-card.json).
- Agent ID: If using an ID from a running AgentVault Registry (e.g.,
-
Configure Credentials: If the target agent requires authentication (e.g.,
apiKeyoroauth2), ensure the necessary credentials are set up using the AgentVault CLI (agentvault config set ...) or environment variables, matching theservice_identifierspecified in the agent's card.
Running the Example¶
Once set up, you can run the example script:
The script will:
- Instantiate the
A2AAgentTool. - Prepare the input (agent reference and text prompt).
- Invoke the tool's
_arunmethod. - The tool will internally use
AgentVaultClientto:- Load the agent card.
- Initiate a task.
- Stream events (though only assistant text messages are captured in this basic example).
- Wait for the task to complete.
- Print the final aggregated text response from the agent.
Note: This example primarily demonstrates the tool's structure and integration. For it to fully succeed, you need a running A2A agent accessible at the specified EXAMPLE_AGENT_REF that can handle the input prompt. You can use the agentvault-server-sdk examples or your own agent implementation.