AI Agent

An autonomous AI agent that runs a ReAct (Reasoning + Acting) loop — it processes a required message input, calls connected tools, optionally reads conversation memory, and returns a response in OpenAI Chat Completion format.

When to Use

Use AI Agent when you need an LLM to reason about inputs and dynamically decide which tools to call:

  • Building a chatbot or conversational assistant
  • Creating a customer support agent that searches knowledge bases and calls APIs
  • Orchestrating multi-step tasks where the LLM decides the next action
  • Processing unstructured data with natural language understanding

Inputs

HandleTypeDescription
messageanyRequired. The input message or data for the agent to process. Typically a user's chat message from an API trigger, or a structured payload from an upstream node. Accepts a string, a chat message object with role and content fields, or any JSON-serializable value.
ToolsdynamicConnect any action node (HTTP Request, Code, MCP Server, Subworkflow, etc.) to give the agent callable tools. Up to 20 tools can be connected — each appears as a new handle slot on the agent's bottom edge.
MemorymemoryConnect a memory plugin (Window Memory or Qdrant Memory) to provide conversation history across requests. One memory provider per agent.

Output

HandleTypeDescription
responseobjectThe agent's final response in OpenAI Chat Completion format. Access via the emit alias ai_agent.

The response output follows the OpenAI Chat Completion spec. Access the agent's answer with {{ ai_agent.choices[0].message.content }}.

{
  "id": "chatcmpl-a1b2c3d4e5f6",
  "object": "chat.completion",
  "created": 1719043200,
  "model": "gpt-4o",
  "choices": [{
    "index": 0,
    "message": { "role": "assistant", "content": "The answer is..." },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 150,
    "completion_tokens": 42,
    "total_tokens": 192
  },
  "_tensorify": {
    "tool_calls": [
      { "name": "http_request", "status": "success", "data": {} }
    ],
    "iterations": 2
  }
}
FieldTypeDescription
idstringUnique completion ID (prefixed chatcmpl-).
objectstringAlways "chat.completion".
creatednumberUnix timestamp when the completion was generated.
modelstringThe model used for this completion.
choices[0].message.contentstringThe agent's final text response.
choices[0].finish_reasonstring"stop" for normal completion, "length" if maxIterations was reached.
usage.prompt_tokensnumberTotal prompt tokens consumed across all iterations.
usage.completion_tokensnumberTotal completion tokens consumed across all iterations.
usage.total_tokensnumberSum of prompt and completion tokens.
_tensorify.tool_callsarrayTool calls made during reasoning. Each entry has name, status ("success" or "error"), and data or error.
_tensorify.iterationsnumberHow many reasoning iterations the agent performed.

The AI Agent always outputs this OpenAI Chat Completion shape. For SDK compatibility, use an API Endpoint trigger with protocol: openai-chat — see Deploy as OpenAI Endpoint. For other trigger types, the completion is available in output.body. See Choosing a Trigger for guidance.

Settings

Model

SettingTypeDefaultDescription
providerselectopenaiLLM provider: OpenAI, Anthropic, or Custom (any OpenAI-compatible endpoint like Ollama, DeepSeek, Together AI).
modelstringgpt-4oModel identifier (e.g. gpt-4o, claude-sonnet-4-20250514). Supports {{ }} bindings for dynamic model selection.
customBaseUrlstringBase URL for custom providers (e.g. http://localhost:11434/v1). Only shown when provider is Custom. Supports bindings.
temperaturenumber0.7Sampling temperature. 0 = deterministic, 2 = creative.

Behavior

SettingTypeDefaultDescription
systemPromptcode-editor (text)You are a helpful assistant.System prompt defining the agent's role and instructions. Supports {{ }} bindings.
maxIterationsnumber10Maximum tool-use iterations before forcing a final answer.
retryCountnumber3Retries for transient LLM API errors (429, 500).

Memory

SettingTypeDefaultDescription
sessionKeystringKey for scoping memory per user or thread. Use bindings like user:{{ input.body.user_id }}. When empty and memory is connected, falls back to a workflow-scoped default key.

Output

SettingTypeDefaultDescription
outputSchemacode-editor (json)JSON Schema for structured output. When set, the agent validates its final answer against this schema. Skipped when tools are connected or streaming is enabled.
streamingbooleantrueStream tokens and tool events in real-time via SSE. Required for the Playground chat mode.

Required Secrets

Environment VariableProviderWhen Required
OPENAI_API_KEYOpenAIWhen provider is openai
ANTHROPIC_API_KEYAnthropicWhen provider is anthropic
CUSTOM_API_KEYCustomWhen provider is custom

Example

Canvas

Build a simple Q&A agent with web search:

  1. Add an API Endpoint trigger with protocol: openai-chat (for SDK compatibility — see Choosing a Trigger)
  2. Add an AI Agent node and connect the trigger's output to the agent's message input (required)
  3. Add an HTTP Request node configured to call a search API — connect it to the agent's Tools handle
  4. Add a Return node and connect the agent's response output to it
  5. Set systemPrompt: "You are a research assistant. Use the search tool to find accurate information before answering."
  6. Set provider and model (e.g. OpenAI / gpt-4o)

The agent receives a user question, decides whether to search, calls the HTTP Request tool if needed, and returns a grounded answer in OpenAI Chat Completion format.

Optional: connect Window Memory to the agent's Memory handle and set a sessionKey binding to scope conversation history per user.

TSL

import manual_trigger from @tensorify/manual-trigger:4.0.0
import ai_agent from @tensorify/ai-agent:1.0.0
import http_request from @tensorify/http-request:3.0.0
import return_node from @tensorify/return:3.0.0

node trigger @tensorify/manual-trigger:4.0.0 {
    mockPayload = """{"message": "What is the weather in NYC?"}"""
}

node agent @tensorify/ai-agent:1.0.0 {
    provider = "openai"
    model = "gpt-4o"
    systemPrompt = "You are a research assistant. Use the search tool to find accurate information before answering."
    maxIterations = 10
}

node search @tensorify/http-request:3.0.0 {
    method = "GET"
    url = "https://api.example.com/search"
}

node respond @tensorify/return:3.0.0 {}

trigger.payload -> agent.message
agent.tools -> search.body
agent.response -> respond.input

Error Handling

The agent has a control output handle On Error. Enable it via the "Error output handle" toggle at the bottom of the settings panel.

The error branch fires when the LLM API call fails after all retries — for example, invalid API key, model not found, or rate limit exhausted. Execution routes through this handle instead of response. Connect it to a Return node to send a custom error response, or to a notification action to alert your team.

When streaming is enabled, an error event is also written to the SSE stream before the branch fires.

Common Gotchas

  • Message input is required: The agent will not run without a wired message input. Always connect a trigger or upstream node before deploying.
  • API keys: Set the provider's API key in your team's Environment Variables (e.g. OPENAI_API_KEY). The agent reads it at runtime.
  • Tool descriptions matter: The agent uses tool names and descriptions to decide which tool to call. Vague names lead to unreliable tool selection.
  • Max iterations: If the agent hits maxIterations, it returns its best answer so far with finish_reason: "length". Increase the limit for complex multi-step tasks.
  • Streaming requires OpenAI Chat protocol: SSE streaming works through the API Endpoint trigger with protocol: openai-chat. The Playground's Chat mode consumes this stream automatically. Manual Trigger does not support streaming.
  • Tool limit: Up to 20 tool connections per agent. If you need more, use MCP Server nodes which bundle multiple tools from a single connection.
  • Default session key: When no sessionKey is set and memory is connected, the agent falls back to agent_memory:{workflow_id}. All users share one conversation buffer — always set a session key in production.
  • Output schema + tools/streaming: When tools are connected or streaming is enabled, outputSchema validation is skipped. The agent returns free-form text instead.

See Also

On this page