magic() function within your async functions.
Magic function
Themagic function enables AI-powered function implementation within your TypeScript code.
Function bodies should call magic with a descriptive prompt.
The task description that guides the AI’s execution. This describes what the function should do.
Optional. An object containing runtime resources that are available during execution.
Resources in scope may be functions, methods, objects, types or any other value.
Optional configuration object for the magic function execution.
Additional information made available in the agent’s system prompt.
Alternatively to providing
premise, you can set explicitly set agent’s system prompt.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.A callback for streaming model generation.
Each streamed text chunk for each magic function call, determined by a unique invocation ID, will route to this callback.
Returns a promise that resolves to the result of specified or inferred return type
T.