Back to Research
AI AgentsTool CallingArchitecture

Dynamic Tool Calling: The Future of AI Agent Flexibility

Learn how dynamic tool calling enables AI agents to adapt and execute actions based on real-time context and user needs.

Meebly AI Team5 min read

Dynamic Tool Calling: The Future of AI Agent Flexibility

Dynamic tool calling represents a paradigm shift in how AI agents interact with external systems and APIs. Rather than being limited to a fixed set of predefined actions, agents can now intelligently select and execute tools based on context, user intent, and real-time requirements.

What is Dynamic Tool Calling?

Dynamic tool calling allows AI agents to:

  • Discover available tools at runtime
  • Evaluate which tools are relevant to the current task
  • Execute multiple tools in sequence or parallel
  • Adapt their approach based on tool responses

This flexibility is crucial for building truly autonomous AI systems that can handle complex, multi-step workflows without hardcoded logic.

The Traditional Approach vs. Dynamic Tool Calling

Traditional Approach

if (userIntent === 'check_order') {
  callOrderAPI(orderId);
} else if (userIntent === 'update_profile') {
  callProfileAPI(userId);
}

This approach requires developers to anticipate every possible scenario and hardcode the logic. It's inflexible and doesn't scale well.

Dynamic Tool Calling with Meebly

// Agent decides which tools to use based on context
const response = await fetch('https://api.meebly.ai/v1/chat', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'YOUR_API_KEY',
  },
  body: JSON.stringify({
    agentId: 'agent_abc123',
    environmentId: 'env_xyz789',
    messages: [{ content: 'Find my last order and update shipping address' }],
  }),
});

The AI agent analyzes the user's request, available tools, and current context to determine the best course of action automatically.

Key Benefits

1. Flexibility

Agents can handle unexpected requests by combining tools in novel ways. If a user asks to "find products similar to my last purchase and add the cheapest one to my cart," the agent can:

  • Retrieve order history
  • Search for similar products
  • Compare prices
  • Add items to cart

All without explicit programming for this specific flow.

2. Scalability

Adding new tools through the Meebly portal doesn't require rewriting agent logic. Simply register the new tool, and the agent can start using it immediately.

3. Context Awareness

Agents consider:

  • User permissions and roles
  • Current application state (via Screen Observer)
  • Previous conversation history
  • Available data and resources

Screen Observer: Visual Context for Agents

Meebly's Screen Observer feature takes context awareness to the next level by allowing agents to "see" what users are viewing:

// Send screen state to agent
function updateMeeblyScreen(screenState) {
  const iframe = document.getElementById('meebly-agent');
  if (!iframe?.contentWindow) return;

  iframe.contentWindow.postMessage(
    {
      type: 'MEEBLY_SCREEN_STATE',
      screenState: {
        ...screenState,
        timestamp: new Date().toISOString(),
      },
    },
    '*'
  );
}

// Usage on product page
updateMeeblyScreen({
  route: '/products/running-shoes-123',
  routeName: 'Product Page',
  entities: {
    product: {
      id: 'running-shoes-123',
      name: 'Trail Running Shoes',
      price: 89.99,
      inStock: true,
    },
  },
});

Now when a user asks "How much is this?" or "Can you add this to my cart?", the agent knows exactly what they're referring to without requiring explicit product IDs.

Real-World Example: E-commerce Agent

Consider an AI shopping assistant built with Meebly AI. You create the agent through the Meebly portal and connect it to your backend APIs:

Step 1: Create Agent in Portal

  1. Navigate to your Meebly dashboard
  2. Create a new agent (conversational type)
  3. Define system instructions
  4. Configure available tools/endpoints

Step 2: Define Your Tools

In the Meebly portal, you define tools that point to your backend:

Search Products Tool:

  • Endpoint: POST /api/products/search
  • Description: Search for products by keyword, category, or filters
  • Parameters: query, filters, limit

Check Inventory Tool:

  • Endpoint: GET /api/inventory/{productId}
  • Description: Check if a product is in stock
  • Parameters: productId, location

Add to Cart Tool:

  • Endpoint: POST /api/cart/items
  • Description: Add a product to the user's shopping cart
  • Parameters: productId, quantity
  • Requires Approval: false

Step 3: Chat with Your Agent

// User asks: "I need running shoes under $100"
const response = await fetch('https://api.meebly.ai/v1/chat', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'YOUR_API_KEY',
    'X-Backend-Token': 'USER_JWT_TOKEN',
  },
  body: JSON.stringify({
    agentId: 'shopping-assistant',
    environmentId: 'production',
    messages: [{ content: 'I need running shoes under $100' }],
  }),
});

// Agent automatically:
// 1. Calls searchProducts with filters
// 2. Checks inventory for available items
// 3. Presents options to user
// 4. When user selects, calls addToCart

The agent dynamically determines which tools to use and in what order—all without hardcoded logic.

Best Practices for Tool Configuration

1. Clear Tool Descriptions

When defining tools in the Meebly portal, provide detailed descriptions:

Tool Name: refundOrder
Description: Initiate a refund for an order. Use only when:
- User explicitly requests a refund
- Order is within 30 days of purchase
- Order has not been refunded already
Parameters:
- orderId (required): The order ID to refund
- reason (required): Reason for refund

2. Tool Approval for Sensitive Actions

Enable human-in-the-loop (HITL) for high-impact tools through the portal settings:

Tool Name: cancelSubscription
Description: Cancel a user subscription
Requires Approval: ✓ Enabled
Approval Timeout: 30 seconds
Parameters:
- subscriptionId
- cancellationReason

When approval is required, Meebly pauses execution and sends a meebly-event with type tool-call-approval:

// Listen for approval requests in SSE stream
data: {
  "type": "meebly-event",
  "event": {
    "type": "tool-call-approval",
    "runId": "run_abc123",
    "toolName": "cancelSubscription",
    "parameters": {
      "subscriptionId": "sub_xyz789",
      "cancellationReason": "User requested"
    }
  }
}

// Approve or decline
await fetch('https://api.meebly.ai/v1/chat/approve', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'YOUR_API_KEY',
  },
  body: JSON.stringify({
    runId: 'run_abc123',
  }),
});

3. Error Handling and Retries

Configure error responses in your backend APIs that agents can interpret:

{
  "success": false,
  "error": "INSUFFICIENT_INVENTORY",
  "message": "Only 2 units available, requested 5",
  "suggestedAction": "adjustQuantity",
  "availableQuantity": 2
}

Multi-Modal Context with Screen Observer

Screen Observer enhances dynamic tool calling by providing visual context:

// E-commerce checkout page
updateMeeblyScreen({
  route: '/checkout',
  routeName: 'Checkout',
  entities: {
    cart: {
      items: [
        { id: 'prod_123', name: 'Running Shoes', quantity: 1, price: 89.99 },
      ],
      total: 89.99,
      taxEstimate: 7.65,
      shippingCost: 0,
    },
    user: {
      hasPaymentMethod: true,
      hasShippingAddress: false,
    },
  },
});

// User: "Why can't I complete my order?"
// Agent sees screen state and knows: no shipping address
// Agent: "I notice you haven't added a shipping address yet.
//         Would you like me to help you add one?"

Implementation with Meebly AI

Meebly makes dynamic tool calling straightforward:

1. Create Agent in Portal

  • Go to dashboard → Create Agent
  • Choose "Conversational" type
  • Write system instructions
  • Configure LLM settings

2. Add Tools/Endpoints

  • Navigate to Tools section
  • Connect your backend APIs
  • Define parameters and descriptions
  • Set approval requirements

3. Chat via API

const response = await fetch('https://api.meebly.ai/v1/chat', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'YOUR_API_KEY',
    'X-Backend-Token': 'USER_JWT',
  },
  body: JSON.stringify({
    agentId: 'your-agent-id',
    environmentId: 'production',
    messages: [{ content: 'Help me find wireless headphones under $150' }],
    screenState: {
      // Optional: current page context
      route: '/products',
      entities: { category: 'electronics' },
    },
  }),
});

The Future of Tool Calling

We're moving toward:

  • Multi-agent tool sharing: Agents collaborating by sharing tool access
  • Visual tool understanding: Agents using Screen Observer to know when tools are relevant
  • Self-improving tools: Tools that learn from usage patterns
  • Predictive tool selection: Agents anticipating needed tools before explicit requests

Conclusion

Dynamic tool calling transforms AI agents from simple chatbots into powerful automation systems. With Meebly AI, you get:

  • Portal-based configuration: No code changes needed to add tools
  • Screen Observer integration: Visual context for smarter decisions
  • HITL support: Built-in approval workflows for sensitive actions
  • Streaming responses: Real-time feedback as tools execute

The key is providing well-defined tools with clear descriptions through the Meebly portal and letting the AI figure out how to combine them to achieve user goals.


Ready to build with dynamic tool calling? Start with Meebly AI and create agents that truly understand and act on user intent—with visual context awareness through Screen Observer.

Ready to Build?

Start building production-ready AI agents with Meebly AI today