SubagentNode is the recommended node type for most use cases. It’s a composite node that can contain multiple tools (webhooks, knowledge bases, MCP servers, WhatsApp templates) and intelligently decides which tool to use based on the conversation context.
from kapso.builder.nodes import SubagentNodefrom kapso.builder.nodes.subagent import ( WebhookTool, KnowledgeBaseTool, McpServerTool, WhatsappTemplateTool, JmespathQuery)# Create a SubagentNodenode = SubagentNode( name="assistant", prompt="You are a helpful assistant. Use the available tools to help users.", global_=False, global_condition=None)
from kapso.builder.nodes.subagent import KnowledgeBaseTool# From texttool = KnowledgeBaseTool( name="policies", knowledge_base_text=""" Return Policy: - 30-day returns for unopened items - 14-day returns for opened items - No returns on sale items """, description="Company policies and procedures")# From filetool = KnowledgeBaseTool.from_file( name="manual", file_path="docs/user_manual.pdf", description="Product user manual")node.add_tool(tool)
from kapso.builder.nodes import SubagentNodefrom kapso.builder.nodes.subagent import ( WebhookTool, KnowledgeBaseTool, WhatsappTemplateTool)# Create the main subagentsubagent = SubagentNode( name="customer_service", prompt="""You are a customer service assistant. Help customers with: - Order inquiries (use order_status tool) - Product questions (use product_info tool) - Policy questions (use policies tool) - Send confirmations when needed (use send_confirmation tool) """)# Order status APIsubagent.add_tool(WebhookTool( name="order_status", url="https://api.store.com/orders/{{order_id}}", http_method="GET", headers={"Authorization": "Bearer {{api_key}}"}, jmespath_query="data.{status: status, tracking: tracking_number}", description="Get order status and tracking information"))# Product knowledge basesubagent.add_tool(KnowledgeBaseTool( name="product_info", knowledge_base_file="products/catalog.pdf", description="Product catalog with specs and pricing"))# Company policiessubagent.add_tool(KnowledgeBaseTool( name="policies", knowledge_base_text=""" Shipping: Free on orders over $50 Returns: 30 days for most items Warranty: 1 year manufacturer warranty """, description="Company policies"))# WhatsApp confirmationsubagent.add_tool(WhatsappTemplateTool( name="send_confirmation", template_name="order_update", phone_number="{{phone}}", template_parameters={"1": "{{order_id}}", "2": "{{status}}"}, description="Send order update via WhatsApp"))
# Create technical support subagenttech_support = SubagentNode( name="tech_support", prompt="Provide technical support using available tools and documentation.")# API health checktech_support.add_tool(WebhookTool( name="system_status", url="https://status.example.com/api/health", http_method="GET", mock_response={"status": "operational", "uptime": "99.9%"}, mock_response_enabled=True, description="Check system status"))# Troubleshooting guidetech_support.add_tool(KnowledgeBaseTool( name="troubleshooting", knowledge_base_text=""" Common Issues: 1. Login problems: Clear cache and cookies 2. Slow performance: Check internet connection 3. Error 500: Contact support """, description="Troubleshooting guide"))# Calculator for technical calculationstech_support.add_tool(McpServerTool( name="tech_calc", url="https://mcp.tools.com/calculator", transport_kind="sse", description="Technical calculations"))
# Global help subagent available from anywherehelp_menu = SubagentNode( name="help_assistant", prompt="Show available options and guide users", global_=True, global_condition="user asks for help, menu, or options")# Add navigation knowledgehelp_menu.add_tool(KnowledgeBaseTool( name="navigation", knowledge_base_text=""" Available Options: 1. Check order status 2. Browse products 3. Technical support 4. Talk to human agent 5. Company policies """, description="Navigation help"))
node = SubagentNode( name="assistant", prompt="""When users ask about: - Orders: Use the 'check_order' tool - Weather: Use the 'weather_api' tool - Policies: Use the 'company_policies' knowledge base - Calculations: Use the 'calculator' MCP server """)
# ✅ Good: Specific and helpfulWebhookTool( name="weather", description="Get current weather conditions for any city")# ❌ Bad: Too vagueWebhookTool( name="weather", description="Weather tool")
# Group related tools in one SubagentNodecustomer_tools = SubagentNode(name="customer_tools")customer_tools.add_tool(order_api)customer_tools.add_tool(customer_kb)customer_tools.add_tool(notification_tool)# Rather than separate nodes for each tool
from kapso.builder import Agentfrom kapso.builder.nodes import SubagentNodefrom kapso.builder.nodes.subagent import ( WebhookTool, KnowledgeBaseTool, McpServerTool, WhatsappTemplateTool)from kapso.builder.agent.constants import START_NODE, END_NODE# Create agentagent = Agent(name="multi_tool_assistant")agent.add_node(START_NODE)agent.add_node(END_NODE)# Create SubagentNode with multiple toolssubagent = SubagentNode( name="main_assistant", prompt="""You are a helpful assistant with access to multiple tools. Use the appropriate tool based on the user's request: - Use order_api for order inquiries - Use weather_api for weather information - Use knowledge_base for general questions - Send confirmations via WhatsApp when requested""")# Add API toolssubagent.add_tool(WebhookTool( name="order_api", url="https://api.example.com/orders/{{order_id}}", http_method="GET", headers={"Authorization": "Bearer {{api_key}}"}, description="Retrieve order information by ID"))subagent.add_tool(WebhookTool( name="weather_api", url="https://api.weather.com/current?city={{city}}", http_method="GET", jmespath_query="data.current", description="Get current weather for a city"))# Add knowledge basesubagent.add_tool(KnowledgeBaseTool( name="company_docs", knowledge_base_text="""Return Policy: Items can be returned within 30 days. Shipping: Free shipping on orders over $50. Business Hours: Monday-Friday 9AM-5PM EST.""", description="Search company policies and information"))# Add WhatsApp templatesubagent.add_tool(WhatsappTemplateTool( name="order_confirmation", template_name="order_confirmed", phone_number="{{customer_phone}}", template_variables={ "1": "{{order_id}}", "2": "{{delivery_date}}" }, description="Send order confirmation via WhatsApp"))# Add node to agentagent.add_node(subagent)# Simple flowagent.add_edge(START_NODE, "main_assistant")agent.add_edge("main_assistant", END_NODE)# The subagent will automatically:# - Understand user intent# - Select the appropriate tool(s)# - Execute them in the right order# - Provide coherent responses