Skip to content

d-agent/dagent-client-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

DAgent Client Demo

Multi-framework examples showcasing dagent-tool integration

This repository demonstrates how to integrate the DAgent decentralized network with popular AI agent frameworks. Each example shows how your agents can discover and route requests to specialized AI agents on-demand.

Frameworks Covered

Framework Directory Description
Google ADK examples/adk/ Native ADK agent with dagent-tool
LangChain examples/langchain/ LangChain agent with custom tool
CrewAI examples/crewai/ CrewAI agent with dagent integration

What This Demo Does

Each example agent uses dagent-tool as a tool, allowing it to:

  • Dynamically discover the best-suited agent from the DAgent network based on natural language requirements
  • Route complex queries to specialized agents (code reviewers, data analysts, creative writers, etc.)
  • Maintain session context across multiple interactions with the same remote agent

Prerequisites

  • Python 3.10+
  • A DAgent API Key — for network authentication
  • Framework-specific API keys (see each example)

Quick Start

1. Clone & Setup

git clone <your-repo-url>
cd dagent_client

# Create virtual environment
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

2. Install for Your Framework

# For Google ADK
pip install dagent-tool[adk]

# For LangChain
pip install dagent-tool[langchain]

# For CrewAI
pip install dagent-tool[crewai]

# Install all frameworks
pip install dagent-tool[all]

3. Configure Environment

Create a .env file in the project root:

# Required for all examples
DAGENT_API_KEY=your-dagent-api-key

# For Google ADK example
GOOGLE_API_KEY=your-google-ai-api-key

# For LangChain example
OPENAI_API_KEY=your-openai-api-key

# For CrewAI example
OPENAI_API_KEY=your-openai-api-key

Project Structure

dagent_client/
├── examples/
│   ├── adk/
│   │   ├── __init__.py
│   │   └── agent.py          # Google ADK example
│   ├── langchain/
│   │   ├── __init__.py
│   │   └── agent.py          # LangChain example
│   └── crewai/
│       ├── __init__.py
│       └── agent.py          # CrewAI example
├── .env                       # API keys (create this)
└── README.md

Google ADK Example

Run

adk run examples/adk
# Or use the web interface
adk web

Code

from google.adk.agents.llm_agent import Agent
from dagent_tool import adk_tool

root_agent = Agent(
    model='gemini-2.5-flash',
    name='root_agent',
    description='A helpful assistant for user questions.',
    instruction='Answer user questions and use adk_tool to connect with specialized agents when needed',
    tools=[adk_tool]
)

LangChain Example

Run

python examples/langchain/agent.py

Code

import asyncio
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from dagent_tool import langchain_tool

llm = ChatOpenAI(model="gpt-4o", temperature=0)

prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a helpful assistant. Use the dagent tool to connect with specialized agents when needed."),
    ("human", "{input}"),
    MessagesPlaceholder(variable_name="agent_scratchpad"),
])

agent = create_openai_functions_agent(llm, [langchain_tool], prompt)
agent_executor = AgentExecutor(agent=agent, tools=[langchain_tool], verbose=True)

# Run
response = agent_executor.invoke({"input": "Review this Python code for bugs..."})
print(response["output"])

CrewAI Example

Run

python examples/crewai/agent.py

Code

from crewai import Agent, Task, Crew
from dagent_tool import crewai_tool

# Create the dagent tool instance
dagent = crewai_tool()

# Define agent with dagent tool
researcher = Agent(
    role='Research Assistant',
    goal='Help users by connecting to specialized agents when needed',
    backstory='An intelligent assistant that can leverage the DAgent network for specialized tasks',
    tools=[dagent],
    verbose=True
)

# Create task
task = Task(
    description='Review this Python function for potential bugs: def add(a, b): return a - b',
    agent=researcher,
    expected_output='A detailed code review with identified issues and fixes'
)

# Run crew
crew = Crew(agents=[researcher], tasks=[task])
result = crew.kickoff()
print(result)

Configuration Options

Customize agent matching through the Requirement model:

from dagent_tool.models import Requirement

requirements = Requirement(
    description="A Python code review assistant",
    skills=["python", "code-review", "best-practices"],
    preferred_llm_provider="OpenAI",  # OpenAI, Anthropic, Google, Llama, Custom
    max_agent_cost=0.01,              # Per-request cost limit
    max_total_agent_cost=1.0,         # Session cost limit
    streaming=False,
    is_multi_agent_system=False
)

Example Interactions

Once running, try prompts like:

Prompt What Happens
"Review this Python function for bugs: def add(a,b): return a-b" Routes to a code review specialist
"Write a haiku about distributed systems" Routes to a creative writing agent
"Explain the CAP theorem in simple terms" May answer directly or route to a technical explainer

Troubleshooting

Issue Solution
AuthenticationError Check your DAGENT_API_KEY is valid
InsufficientCreditsError Top up credits at dagent.network
NoAgentFoundError Broaden your requirements or remove skill constraints
ModuleNotFoundError: google.adk Run pip install dagent-tool[adk]
ModuleNotFoundError: langchain Run pip install dagent-tool[langchain]
ModuleNotFoundError: crewai Run pip install dagent-tool[crewai]

Learn More

License

MIT

About

Example integrations of dagent-tool with ADK, LangChain, and CrewAI frameworks

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published