magentic
Basic Information
Magentic is a Python library designed to integrate large language models directly into Python code by turning prompts into callable functions. It provides decorators such as @prompt, @chatprompt and @prompt_chain so developers can define prompt templates as function signatures and receive typed, structured outputs. The project supports function calling where the LLM can return a FunctionCall object that is executed by local functions, and it can automatically resolve multi-step prompt chains. Magentic also supports streaming of text and structured objects, asyncio for concurrent generation, and configurable backends for OpenAI, Anthropic, LiteLLM, Mistral and Ollama-compatible APIs. The library emphasizes type annotations, pydantic models for structured outputs, configurable model contexts, and environment-variable configuration to make LLM-driven functionality testable and composable within standard Python projects.