Documentation Index
Fetch the complete documentation index at: https://mintlify.com/pydantic/monty/llms.txt
Use this file to discover all available pages before exploring further.
Overview
This guide shows you how to build a simple agent using Monty. The agent will make iterative calls to an LLM until it receives a final response.The Agent Pattern
A basic agent loop:- Maintains a list of messages
- Calls the LLM with the current message history
- If the LLM returns more messages, append them and loop
- If the LLM returns a string, return it as the final output
Complete Example
Write the agent code
Define your agent logic that Monty will execute:
The agent uses
call_llm() which is an external function you’ll provide to Monty.Define type stubs
Provide type definitions for Monty’s type checker:
Type stubs tell Monty what types to expect. The
NotImplementedError() indicates this function will be provided externally.Implement the external function
Provide your host implementation of
call_llm():This is a mock implementation. In a real agent, you would call an actual LLM API here.
How It Works
call_llm() runs in your host application with full network access.
Key Concepts
Inputs
External Functions
Type Checking
Execution Flow
- Monty parses and type-checks your agent code
- Agent starts executing with the provided inputs
- When
call_llm()is called, Monty pauses and calls your host function - Host function returns, Monty resumes execution
- Agent continues until it returns a final result
This pause-and-resume pattern allows your agent code to call external services while remaining in a secure sandbox.
Next Steps
- Learn about iterative execution for more control
- See PydanticAI integration for a full framework
- Explore resource limits to control agent execution
