> For the complete documentation index, see [llms.txt](https://whitepaper.aitech.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whitepaper.aitech.io/agentforge/blocks/agent.md).

# agent

The Agent block serves as the interface between your workflow and Large Language Models (LLMs). It executes inference requests against various AI providers, processes natural language inputs according to defined instructions, and generates structured or unstructured outputs for downstream consumption.

### Overview

The Agent block enables you to:

* **Process natural language**: Analyze user input and generate contextual responses
* **Execute AI-powered tasks**: Perform content analysis, generation, and decision-making
* **Call external tools**: Access APIs, databases, and services during processing
* **Generate structured output**: Return JSON data that matches your schema requirements

### Configuration Options

#### System Prompt

The system prompt establishes the agent's operational parameters and behavioral constraints. This configuration defines the agent's role, response methodology, and processing boundaries for all incoming requests.

```markdown
You are a helpful assistant that specializes in financial analysis.
Always provide clear explanations and cite sources when possible.
When responding to questions about investments, include risk disclaimers.
```

#### User Prompt

The user prompt represents the primary input data for inference processing. This parameter accepts natural language text or structured data that the agent will analyze and respond to. Input sources include:

* **Static Configuration**: Direct text input specified in the block configuration
* **Dynamic Input**: Data passed from upstream blocks through connection interfaces
* **Runtime Generation**: Programmatically generated content during workflow execution

#### Model Selection

The Agent block supports multiple LLM providers through a unified inference interface. Available models include:

* **OpenAI Models**: GPT-5, GPT-4o, o1, o3, o4-mini, gpt-4.1 (API-based inference)
* **Anthropic Models**: Claude 3.7 Sonnet (API-based inference)
* **Google Models**: Gemini 2.5 Pro, Gemini 2.0 Flash (API-based inference)
* **Alternative Providers**: Groq, Cerebras, xAI, DeepSeek (API-based inference)
* **Local Deployment**: Ollama-compatible models (self-hosted inference)

#### Temperature

Control the creativity and randomness of responses:

{% tabs %}
{% tab title="Low (0-0.3)" %}
More deterministic, focused responses. Best for factual tasks, customer support, and situations where accuracy is critical.
{% endtab %}

{% tab title="Medium (0.3-0.7)" %}
Balanced creativity and focus. Suitable for general purpose applications that require both accuracy and some creativity.
{% endtab %}

{% tab title="High (0.7-2.0)" %}
More creative, varied responses. Ideal for creative writing, brainstorming, and generating diverse ideas.
{% endtab %}
{% endtabs %}

The temperature range (0-1 or 0-2) varies depending on the selected model.

#### API Key

Your API key for the selected LLM provider. This is securely stored and used for authentication.

#### Tools

Tools extend the agent's capabilities through external API integrations and service connections. The tool system enables function calling, allowing the agent to execute operations beyond text generation.

**Tool Integration Process**:

1. Access the Tools configuration section within the Agent block
2. Select from 60+ pre-built integrations or define custom functions
3. Configure authentication parameters and operational constraints

**Available Tool Categories**:

* **Communication**: Gmail, Slack, Telegram, WhatsApp, Microsoft Teams
* **Data Sources**: Notion, Google Sheets, Airtable, Supabase, Pinecone
* **Web Services**: Firecrawl, Google Search, Exa AI, browser automation
* **Development**: GitHub, Jira, Linear repository and issue management
* **AI Services**: OpenAI, Perplexity, Hugging Face, ElevenLabs

**Tool Execution Control**:

* **Auto**: Model determines tool invocation based on context and necessity
* **Required**: Tool must be called during every inference request
* **None**: Tool definition available but excluded from model context

#### Response Format

The Response Format parameter enforces structured output generation through JSON Schema validation. This ensures consistent, machine-readable responses that conform to predefined data structures:

```json
{
  "name": "user_analysis",
  "schema": {
    "type": "object",
    "properties": {
      "sentiment": {
        "type": "string",
        "enum": ["positive", "negative", "neutral"]
      },
      "confidence": {
        "type": "number",
        "minimum": 0,
        "maximum": 1
      }
    },
    "required": ["sentiment", "confidence"]
  }
}
```

This configuration constrains the model's output to comply with the specified schema, preventing free-form text responses and ensuring structured data generation.

#### Accessing Results

After an agent completes, you can access its outputs:

* **`<agent.content>`**: The agent's response text or structured data
* **`<agent.tokens>`**: Token usage statistics (prompt, completion, total)
* **`<agent.tool_calls>`**: Details of any tools the agent used during execution
* **`<agent.cost>`**: Estimated cost of the API call (if available)

### Advanced Features

#### Memory Integration

Agents can maintain context across interactions using the memory system:

```javascript
// In a Function block before the agent
const memory = {
  conversation_history: previousMessages,
  user_preferences: userProfile,
  session_data: currentSession,
};
```

#### Structured Output Validation

Use JSON Schema to ensure consistent, machine-readable responses:

```json
{
  "type": "object",
  "properties": {
    "analysis": { "type": "string" },
    "confidence": { "type": "number", "minimum": 0, "maximum": 1 },
    "categories": { "type": "array", "items": { "type": "string" } }
  },
  "required": ["analysis", "confidence"]
}
```

#### Error Handling

Agents automatically handle common errors:

* API rate limits with exponential backoff
* Invalid tool calls with retry logic
* Network failures with connection recovery
* Schema validation errors with fallback responses

### Inputs and Outputs

{% tabs %}
{% tab title="Configuration" %}

* **System Prompt**: Instructions defining agent behavior and role
* **User Prompt**: Input text or data to process
* **Model**: AI model selection (OpenAI, Anthropic, Google, etc.)
* **Temperature**: Response randomness control (0-2)
* **Tools**: Array of available tools for function calling
* **Response Format**: JSON Schema for structured output
  {% endtab %}

{% tab title="Variables" %}

* **agent.content**: Agent's response text or structured data
* **agent.tokens**: Token usage statistics object
* **agent.tool\_calls**: Array of tool execution details
* **agent.cost**: Estimated API call cost (if available)
  {% endtab %}

{% tab title="Results" %}

* **Content**: Primary response output from the agent
* **Metadata**: Usage statistics and execution details
* **Access**: Available in blocks after the agent
  {% endtab %}
  {% endtabs %}

### Example Use Cases

#### Customer Support Automation

Scenario: Handle customer inquiries with database access

1. User submits support ticket via API block
2. Agent processes inquiry with product database tools
3. Agent generates response and creates follow-up ticket
4. Response block sends reply to customer

#### Multi-Model Content Analysis

Scenario: Analyze content with different AI models

1. Function block processes uploaded document
2. Agent with GPT-4o performs technical analysis
3. Agent with Claude analyzes sentiment and tone
4. Function block combines results for final report

#### Tool-Powered Research Assistant

Scenario: Research assistant with web search and document access

1. User query received via input
2. Agent searches web using Google Search tool
3. Agent accesses Notion database for internal docs
4. Agent compiles comprehensive research report

### Best Practices

* **Be specific in system prompts**: Clearly define the agent's role, tone, and limitations. The more specific your instructions are, the better the agent will be able to fulfill its intended purpose.
* **Choose the right temperature setting**: Use lower temperature settings (0-0.3) when accuracy is important, or increase temperature (0.7-2.0) for more creative or varied responses
* **Leverage tools effectively**: Integrate tools that complement the agent's purpose and enhance its capabilities. Be selective about which tools you provide to avoid overwhelming the agent. For tasks with little overlap, use another Agent block for the best results.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://whitepaper.aitech.io/agentforge/blocks/agent.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
