Skip to main content

agentic

A function used to create an agentic function.
async function agentic<T>(
    userPrompt: string,
    scope?: object,
    config?: {
      model?: ModelStrings,
      premise?: string,
      system?: string | Template,
      maxTokens?: number | MaxTokens,
      onUsage?: (usage: Usage) => void;
      listener?: (iid: string, chunk: Chunk) => void,
    },
): Promise<T>;
Parameters
prompt
string
The task description that guides the underlying agent’s execution. This describes what the function should do.
scope
object
Optional. An object containing runtime resources that are available during execution. Resources in scope may be functions, methods, objects, types or any other value.
config
object
Optional configuration object for the agentic function execution.
config.premise
string
An optional premise for the agentic function. This will be attached to the system prompt of all invocations of this agentic function.
This argument cannot be provided along with the config.system argument.
config.system
string | Template
An optional system prompt for the agentic function. This will be the system prompt of all invocations of this agentic function. Either
  • a string, or
  • or an instance of Template.
This argument cannot be provided along with the config.premise argument.
config.model
string
The model which backs your agent.One of:
  • 'openai:gpt-3.5-turbo'
  • 'openai:gpt-4o'
  • 'openai:gpt-4.1'
  • 'openai:gpt-5'
  • 'anthropic:claude-sonnet-4'
  • 'anthropic:claude-opus-4.1'
  • 'anthropic:claude-sonnet-4.5'
  • 'anthropic:claude-opus-4.5'
or any OpenRouter model slug.
The default model is openai:gpt-4.1.
config.maxTokens
number | MaxTokens
Either
  • the maximum number of output tokens generated in a single round of inference in a single invocation, or
  • an instance of MaxTokens for more fine-grained control.
See MaxTokens for information on default values.
config.onUsage
(usage: Usage) => void
A callback to obtain the token usage of an agentic function for the last invocation.
config.listener
(iid: string, chunk: Chunk) => void
A callback for streaming model generation. Each streamed text chunk for each agentic function call, determined by a unique invocation ID, will route to this callback.
Returns
Promise<T>
Returns a promise that resolves to the result of specified or inferred return type T.