A community-driven registry for Claude, Cursor, Windsurf, Cline & more. Not affiliated with Anthropic.
Are you the author? Sign in to claim
Building Agents with LLM structured generation (BAML), MCP Tools, and 12-Factor Agents principles
Building Agents with LLM structured generation (BAML), MCP Tools, and 12-Factor Agents principles
This repository shares useful patterns I use when working with BAML. Note: The API may unexpectedly change with future minor versions; therefore, install with specific version constraints:
pip install "baml-agents>=0.46.1,<0.47.0"
Found this useful? Star the repo on GitHub to show support and follow for updates. Also, find me on Discord if you have questions or would like to join a discussion!
This project is maintained independently by Elijas and is not affiliated with the official BAML project.
/notebooks: Core Tutorials & Examples. Contains curated Jupyter notebooks demonstrating key features and recommended patterns. Start here to learn baml-agents./explorations: Experimental & Niche Content. Holds prototypes, tests, and examples for specific or advanced use cases. Content may be less polished or stable. See the explorations README./baml_agents/devtools: Developer Utilities. Contains helper scripts for project maintenance, development workflows, and automating tasks (e.g., updating baml generator versions). See the devtools README.The primary tutorials are located in the /notebooks directory:
ActionRunner for flexible structured outputs.ActionRunner in action, automatically discovering and integrating tools from MCP servers with minimal configuration.Action classes) with standardized MCP tools (like calculators or time servers) managed by ActionRunner.GetNextAction), see it execute tools, and observe how it uses the results to progress.JupyterBamlMonitor for transparent inspection of the underlying LLM interactions.[!TIP] The code below is trimmed for brevity to illustrate the core concepts. Some function names or setup steps may differ slightly from the full notebook implementation for clarity in this example. The full, runnable code is available in the notebook Simple Agent Demonstration (notebooks/05_simple_agent_demo.ipynb)
def get_weather_info(city: str):
return f"The weather in {city} is 63 degrees fahrenheit with cloudy conditions."
def stop_execution(final_answer: str):
return f"Final answer: {final_answer}"
r = ActionRunner() # Doing an action means using a tool
# Adding a tool to allow the agent to do math
r.add_from_mcp_server(server="uvx mcp-server-calculator")
# Adding a tool to get the current time
r.add_from_mcp_server(server="uvx mcp-timeserver") # Note: you can also add URLs
# Adding a tool to get the current weather
r.add_action(get_weather_info)
# Adding a tool to let the agent stop execution
r.add_action(stop_execution)
async def execute_task(llm, task: str) -> str:
interactions = []
while True:
action = await llm.GetNextAction(task, interactions)
if result := is_result_available(action):
return result
result = r.run(action)
interactions.append(new_interaction(action, result))
llm = LLMClient("gpt-4.1-nano")
task = r.execute_task(llm, "State the current date along with avg temp between LA, NY, and Chicago in Fahrenheit.")
To try it yourself, check out the notebook Simple Agent Demonstration (notebooks/05_simple_agent_demo.ipynb).
class NextAction {
@@dynamic
}
class NextAction {
chosen_action MyTool1 | MyTool2 | MyTool3
}
pseudocode:
NextAction.add_property("chosen_action", MyTool1 | MyTool2 | MyTool3)
r = ActionRunner(TypeBuilder)
r.add_action(MyTool1)
r.add_action(MyTool2)
r.add_action(MyTool3)
or just
r.add_from_mcp_server(calculator_mcp)
to bulk-add all tools from some mcp server
tb = r.tb(T.BamlCustomTools_NextAction)
action = b.BamlCustomTools_GetNextAction(
question, baml_options={"tb": tb}
)
MyTool1 and {"name": "John"}tool_output = MyTool1(name="John")To run code from the notebooks/ folder, you'll first need to:
uv python package manager.uv sync --devuv run baml-cli generate
.baml file.MCP server integration for DaVinci Resolve Studio
mcp-language-server gives MCP enabled clients access semantic tools like get definition, references, rename, and diagnos
Run Claude Code as an MCP server so any agent can delegate coding tasks to it
Browser automation using accessibility snapshots instead of screenshots