Documentation Index Fetch the complete documentation index at: https://docs.getbindu.com/llms.txt
Use this file to discover all available pages before exploring further.
Simple Q&A agent that answers questions on demand.
Code
"""AG2 (formerly AutoGen) agent wrapped with Bindu.
A simple Q&A agent using AG2's ConversableAgent, exposed as a
Bindu-compatible networked service with identity, communication,
and payment capabilities.
"""
import os
from autogen import ConversableAgent, LLMConfig
from bindu.penguin import bindufy
from dotenv import load_dotenv
load_dotenv()
llm_config = LLMConfig(
{
"model" : os.getenv( "LLM_MODEL" , "openai/gpt-4o-mini" ),
"api_key" : os.environ.get( "OPENROUTER_API_KEY" , "" ),
"base_url" : "https://openrouter.ai/api/v1" ,
}
)
config = {
"author" : "ag2-community" ,
"name" : "ag2-assistant" ,
"description" : (
"A research assistant powered by AG2 (formerly AutoGen). "
"Ask any question and get a clear, concise answer."
),
"deployment" : {
"url" : "http://localhost:3773" ,
"expose" : True ,
"cors_origins" : [ "http://localhost:5173" ],
},
}
def handler ( messages : list[dict[ str , str ]]):
"""Forward messages to the AG2 agent and return its response."""
if not messages:
return [{ "role" : "assistant" , "content" : "No input provided." }]
user_input = messages[ - 1 ].get( "content" , "" )
if not user_input:
return [{ "role" : "assistant" , "content" : "Empty message." }]
# Fresh agents per request to avoid state leakage
agent = ConversableAgent(
name = "assistant" ,
system_message = (
"You are a helpful research assistant. Provide "
"clear, concise answers to questions. When you "
"don't know something, say so."
),
llm_config = llm_config,
)
user_proxy = ConversableAgent(
name = "user" , human_input_mode = "NEVER" ,
)
result = user_proxy.initiate_chat(
agent, message = user_input, max_turns = 1
)
if not result.chat_history:
return [{ "role" : "assistant" , "content" : "No response." }]
reply = result.chat_history[ - 1 ].get( "content" , "" )
return [{ "role" : "assistant" , "content" : reply}]
if __name__ == "__main__" :
bindufy(config, handler)
How It Works
Instructions
Defines agent as helpful research assistant
Provides clear, concise answers to questions
Admits when information is unknown
Maintains professional, helpful tone
Tools
ConversableAgent: Multi-agent conversation framework
UserProxy: Handles message forwarding without human input
Fresh agent instances per request prevent state leakage
Model
gpt-4o-mini: Cost-effective model for Q&A
Via OpenRouter API integration
Configurable through environment variables
Dependencies
uv init
uv add bindu pyautogen python-dotenv
Environment Setup
Create .env file:
OPENROUTER_API_KEY = your_openrouter_api_key_here
LLM_MODEL = openai/gpt-4o-mini
Run
Examples:
“What are the main differences between AG2 and AutoGen?”
“How do I create a multi-agent conversation with AG2?”
“What are the key features of AG2 agents?”
Example API Calls
{
"jsonrpc" : "2.0" ,
"method" : "message/send" ,
"params" : {
"message" : {
"role" : "user" ,
"kind" : "message" ,
"messageId" : "9f11c870-5616-49ad-b187-d93cbb100001" ,
"contextId" : "9f11c870-5616-49ad-b187-d93cbb100002" ,
"taskId" : "9f11c870-5616-49ad-b187-d93cbb100003" ,
"parts" : [
{
"kind" : "text" ,
"text" : "What are the main differences between AG2 and AutoGen?"
}
]
},
"configuration" : {
"acceptedOutputModes" : [ "application/json" ]
}
},
"id" : "9f11c870-5616-49ad-b187-d93cbb100003"
}
{
"jsonrpc" : "2.0" ,
"method" : "tasks/get" ,
"params" : {
"taskId" : "9f11c870-5616-49ad-b187-d93cbb100003"
},
"id" : "9f11c870-5616-49ad-b187-d93cbb100004"
}
Frontend Setup
# Clone the Bindu repository
git clone https://github.com/GetBindu/Bindu
# Navigate to frontend directory
cd frontend
# Install dependencies
npm install
# Start frontend development server
npm run dev
Open http://localhost:5173 and try to chat with the AG2 assistant