> ## Documentation Index
> Fetch the complete documentation index at: https://docs.opencompany.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Agent Workflow

> Build an AI agent with conversation memory and tools

# AI Agent Workflow

Create an intelligent AI agent that remembers conversation history and can use tools.

## What You'll Build

A chatbot that:

* Maintains conversation context across messages
* Uses an AI model (OpenAI, Claude, Gemini, and more)
* Responds via webhook

## Prerequisites

* MachinaOs running locally
* An AI provider API key (OpenAI, Anthropic, Google, or any of the 11 supported providers)

## Step 1: Add the AI Agent

1. Drag **AI Agent** from the AI Agents category
2. This is the core of your intelligent assistant

The AI Agent node has several handles:

* **Main Input** (`input-main`, left) - Receives the user prompt
* **Memory** (`input-memory`, left diamond) - Connects to a Simple Memory node
* **Skill** (`input-skill`, bottom diamond) - Connects skill nodes
* **Tools** (`input-tools`, bottom diamond) - Connects tool nodes
* **Output** (`output-main`, right) - The agent's response

## Step 2: Choose the Provider and Model

The AI Agent picks its own provider and model directly in its parameters. There is no separate model handle to wire up.

1. Click the AI Agent to open its parameter panel
2. Set the **Provider** and **Model**:

```
Provider: anthropic
Model: claude-opus-4-8
Temperature: 0.7
```

You can pick any of the 11 providers: OpenAI, Anthropic, Gemini, OpenRouter, Groq, Cerebras, DeepSeek, Kimi, Mistral, Ollama, or LM Studio. Model options update automatically based on the provider you choose (for example, OpenAI offers `gpt-5.5`, Anthropic offers `claude-opus-4-8` / `claude-sonnet-4-6`, Gemini offers `gemini-3.5-flash`).

<Tip>
  Claude excels at reasoning, Gemini handles multimodal input, and Ollama / LM Studio let you run local models on your own machine. The standalone **Chat Model** nodes (e.g. OpenAI Chat Model, Claude Chat Model) are for using a model on its own outside an agent -- you do not need one to power the AI Agent.
</Tip>

## Step 3: Add Conversation Memory

1. Drag **Simple Memory** from the AI Tools category
2. Connect its output to the AI Agent's **Memory** input (`input-memory`, the left diamond handle)
3. Configure:

```
Session ID: default
Window Size: 10
```

Simple Memory keeps a rolling window of the most recent message pairs (set by **Window Size**). The conversation is stored as editable markdown you can view and change right in the parameter panel.

<Info>
  Enable **Long-Term Memory** on the Simple Memory node to archive older messages into a vector store for semantic recall beyond the recent window.
</Info>

## Step 4: Add a Webhook Trigger

1. Drag **Webhook Trigger** from the Triggers category
2. Connect its output to the AI Agent's main input (`input-main`)
3. Configure:

```
Path: chat
Method: POST
```

## Step 5: Add a Webhook Response

1. Drag **Webhook Response** from Utilities
2. Connect the AI Agent's output to Webhook Response
3. Configure:

```
Status Code: 200
Body: {{aiAgent.response}}
Content Type: application/json
```

## Complete Workflow

```
[Webhook Trigger] --> [AI Agent] --> [Webhook Response]
                         ^
                         | input-memory
                         |
               [Simple Memory]
```

The AI Agent's provider and model are set in its own parameters (Step 2), so there is no separate model node to connect.

## Step 6: Configure the Agent Prompt

Click on the AI Agent and set the **System Message** field:

```
You are a helpful assistant. You remember our conversation history.
Be concise and friendly in your responses.
```

## Step 7: Deploy and Test

1. Click **Deploy**
2. Test with curl:

```bash theme={null}
# First message
curl -X POST http://localhost:3010/webhook/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Hi, my name is Alex"}'

# Second message (agent remembers your name)
curl -X POST http://localhost:3010/webhook/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "What is my name?"}'
```

The agent should respond with your name, demonstrating memory!

## Advanced: Multiple Sessions

Use different session IDs for different conversations:

```
Session ID: {{webhookTrigger.body.user_id}}
```

This creates separate memory for each user.

## Advanced: Window Size

For long conversations, adjust **Window Size** to control how much history the agent sees:

```
Window Size: 10
```

This keeps only the last 10 message exchanges in short-term memory. Turn on **Long-Term Memory** if you also want older messages retrievable via semantic search.

## Troubleshooting

<Accordion title="Agent doesn't remember previous messages">
  * Ensure Simple Memory is connected to the memory input (diamond handle)
  * Check that Session ID is consistent between requests
  * Memory is saved after each exchange automatically
</Accordion>

<Accordion title="API key not found">
  * Click the key icon in the toolbar
  * Add your API key for the provider you're using
  * Keys are stored securely and encrypted
</Accordion>

## Next Steps

<CardGroup cols={2}>
  <Card title="WhatsApp Automation" icon="whatsapp" href="/tutorials/whatsapp-automation">
    Connect your agent to WhatsApp
  </Card>

  <Card title="AI Models Reference" icon="brain" href="/nodes/ai-models">
    Compare AI providers
  </Card>
</CardGroup>
