---
title: text
description: API Reference for text.
---

# `text()`

Generates a text response using the configured AI model and tools

```ts showLineNumbers copy
const agent = new Agent({...});

// Simple text generation
const textGeneration = await agent.text({
   messages: ["What's the weather like?"]
});

// With step tracking
const stepTrackResult = await agent.text({
   messages: ["Send an email to john@example.com"],
   onStepFinish: (step) => {
    console.log(`Step completed: ${step}`)
   },
   maxSteps: 3
});
```

## API Signature

### Parameters

<PropertiesTable
  content={[
    {
      name: "messages",
      type: "Array<string>",
      description: "An array of messages to generate process",
    },
    {
      name: "onStepFinish",
      type: "(step: string) => void;",
      isOptional: true,
      description:
        "Callback function called after each step. Receives step details as a JSON string",
    },
    {
      name: "maxSteps",
      type: "number",
      isOptional: true,
      description:
        "Maximum number of tool execution steps allowed. (Defaults to 5)",
    },
  ]}
/>

### Returns

<PropertiesTable
  content={[
    {
      name: "text",
      type: "string",
      isOptional: true,
      description: "The generated text response",
    },
    {
      name: "toolCalls",
      type: "Array<ToolCall>",
      isOptional: true,
      description: "The tool calls made during the text generation process",
      properties: [
        {
          type: "ToolCall",
          parameters: [
            {
              name: "toolName",
              type: "string",
              description: "The name of the tool",
            },
            {
              name: "args",
              type: "any",
              description: "The arguments passed to the tool",
            },
          ],
        },
      ],
    },
    {
      name: "error",
      type: "string",
      isOptional: true,
      description: "Error message if the tool execution fails",
    },
  ]}
/>
