@magic decorator.
Magic decorator
This function is primarily meant to be used as a decorator on functions that you wish to be AI-implemented. Function bodies should contain a descriptive doc-string, but otherwise be empty (body contains...).
A list of runtime resources that are in scope and which may be used during the execution of the magic function.
Resources in scope may be arbitrary Python functions, methods, objects, iterators, types or any other Python value.
An optional system prompt for the magic function. This will be the system prompt of all invocations of this magic function.
An optional premise for the magic function. This will be attached to the system prompt of all invocations of this magic function.
The string of a path to a
.json file representing an MCP configuration. Any servers and/or tools of servers outlined in the config can be used during the execution of the magic function.Whether to persist the function state/history between calls. Defaults to
False.The model used to execute the
magic function.One of:openai:gpt-3.5-turboopenai:gpt-4oopenai:gpt-4.1openai:gpt-5anthropic:claude-sonnet-4anthropic:claude-opus-4.1anthropic:claude-sonnet-4.5
openai:gpt-4.1.The maximum number of tokens that the agent can generate during one round of inference.Defaults to
2048.Optional listener constructor for logging the magic function’s activity and chat history.
The default agent listener is the
StandardListener, but can be changed for all agents and magic functions in the current scope with set_default_agent_listener.
If a context-specific logger is used in the current scope, the logger will be added to the listener: if the listener is None, then the listener will be set to:- the default agent listener, if it is not
None, or - the
StandardListener, if the default agent listener isNone