Skip to main content
Tools and context are two powerful ways to enhance Marvin’s capabilities, allowing agents to perform actions beyond their built-in abilities and access additional information when completing tasks.

Tools: Extending Agent Capabilities

Tools are Python functions that agents can call during task execution. They allow agents to:
  • Access external systems and APIs
  • Perform calculations or data processing
  • Interact with files, databases, or other resources
  • Execute custom business logic
When an agent has access to a tool, it can decide when and how to use it based on the task requirements. The agent sees the tool’s name, docstring, and signature, and can call it with appropriate arguments.

Creating Effective Tools

The best tools are:
  1. Focused: Each tool should do one thing well
  2. Well-documented: Clear docstrings help the agent understand when and how to use the tool
  3. Type-hinted: Type annotations help the agent understand what inputs and outputs to expect

Providing Tools

Tools can be provided at different levels:

Context: Providing Additional Information

Context is additional information you provide to a task or agent to help it generate better responses. Unlike tools (which are functions the agent can call), context is static data that informs the agent’s understanding.
Context can include:
  • Background information
  • User preferences or history
  • Data to analyze or reference
  • Previous conversation history
  • System state or configuration

Using Context Effectively

For best results with context:
  1. Be selective: Include only relevant information to avoid overwhelming the agent
  2. Structure appropriately: Organize complex context into clear sections
  3. Use descriptive keys: Name context variables clearly so the agent understands what each piece represents

Context in Prompts

You can reference context directly in your prompts using string formatting:

Combining Tools and Context

Tools and context work together to create powerful AI workflows:
In this example:
  • The context provides the data and business information
  • The tool gives the agent the ability to perform statistical analysis
  • Together, they enable the agent to make informed recommendations

Best Practices

  • Security: Only provide tools that you’re comfortable with the agent using
  • Error handling: Ensure tools handle errors gracefully and provide helpful error messages
  • Complexity: Start with simple tools and context, then add complexity as needed
  • Testing: Test your tools independently before providing them to agents
  • Observability: Monitor tool usage to understand how agents are using them
By effectively combining tools and context, you can create AI workflows that leverage both the reasoning capabilities of large language models and the precision of traditional code.