Build an AI Agent

This guide walks you through building, testing, and deploying an AI agent that can call tools and maintain conversation memory. By the end, you'll have a deployed agent accessible via any OpenAI SDK client.

Uses: AI Agent, HTTP Request, Window Memory, API Endpoint, Return Time: ~15 minutes


Prerequisites

  • A Tensorify workspace at app.tensorify.io
  • An OpenAI API key (or Anthropic, or any OpenAI-compatible provider)
  • CLI installed if deploying locally: curl -fsSL https://cli.tensorify.io/install | sh

1. Create a Workflow

Create a new workflow from the dashboard. You'll see an empty canvas with a node palette on the left.

2. Add a Trigger

Drag an API Endpoint trigger onto the canvas. This creates a programmable HTTP endpoint for your agent.

Configure the trigger:

  • Path: /v1 (for OpenAI-compatible access)
  • Allowed Methods: GET, POST
  • Response Mode: Use Workflow Response
  • Protocol: OpenAI Chat (messages[] ↔ ChatCompletion)

Setting the protocol to openai-chat makes your agent accessible via any OpenAI SDK. The trigger translates messages[] into workflow input and formats the response as a ChatCompletion.

3. Add an AI Agent

Drag an AI Agent node onto the canvas. Connect the trigger's POST output handle to the agent's message input.

Configure the agent:

  • Provider: OpenAI (or your preferred provider)
  • Model: gpt-4o
  • System Prompt: Write clear instructions for what the agent should do

Example system prompt for a research assistant:

You are a research assistant. When asked a question:
1. Search for relevant information using the available tools
2. Synthesize the findings into a clear, accurate answer
3. Cite your sources when possible

Be concise and factual. If you don't know something, say so.

4. Add Tools

Tools give your agent capabilities beyond text generation. Drag an HTTP Request node onto the canvas and connect it to the agent's Tools handle.

Configure the HTTP Request tool:

  • Label: Search API (the agent sees this name)
  • Method: GET
  • URL: https://api.example.com/search?q={{ "{{ input.query }}" }}

The agent decides when and how to call tools based on their names and the current conversation. Clear tool names lead to better tool selection.

You can connect multiple tools — each one appears as a new handle slot on the agent node. Common tool combinations:

  • HTTP Request for API calls
  • Code for custom Python logic
  • MCP Server for connecting to MCP-compatible services

5. Add Memory

For multi-turn conversations, add a Window Memory node and connect it to the agent's Memory handle.

Configure:

  • Window Size: 20 (keeps the last 20 messages)
  • Persistent: true (survives workflow restarts)
  • Session Key: session:{{ "{{ api_request.headers["x-tensorify-session-id"] }}" }} (scopes memory per session — the Playground and OpenAI SDK clients send this automatically)

6. Add a Return Node

Drag a Return node and connect the agent's response output to it. This sends the agent's answer back as the HTTP response.

7. Set Environment Variables

Go to Settings > Environment Variables in the sidebar and add:

  • OPENAI_API_KEY: Your OpenAI API key

8. Test from the Canvas

  1. Ensure your runner is connected (tensorify runner start)
  2. Click Test in the canvas toolbar
  3. Select the Return node as the target
  4. Click Run to Selected

The agent will process the mock payload, potentially call tools, and return a response. Check the output in the test results panel.

9. Deploy

Click Deploy in the toolbar:

  1. Choose your execution mode: Tensorify Cloud (managed) or Self-Hosted (CLI runner)
  2. Copy the trigger URL — this is your agent's endpoint

10. Connect with the OpenAI SDK

Your deployed agent is now accessible via the OpenAI SDK:

from openai import OpenAI

client = OpenAI(
    base_url="https://triggers.tensorify.io/h/YOUR_HOOK_ID/v1",
    api_key="your-bearer-token"  # the secret from your API trigger's auth settings
)

response = client.chat.completions.create(
    model="my-agent",
    messages=[
        {"role": "user", "content": "What are the latest trends in AI?"}
    ]
)

print(response.choices[0].message.content)

11. Test with the Playground

Open the Playground tab in the canvas bottom bar. Because the API trigger protocol is set to openai-chat, the Playground automatically opens in Chat mode.

Type a message and press Enter. You'll see the agent's response stream in real-time. The Playground manages session IDs automatically via the X-Tensorify-Session-Id header, so multi-turn conversations work out of the box.

The Playground sends real requests to your deployed endpoint — make sure the workflow is deployed before testing.

What's Next?

  • Add more tools: Connect Code nodes for custom logic or MCP Server nodes for external integrations
  • Upgrade memory: Switch to Qdrant Memory for semantic search over long conversation histories
  • Enable streaming: Set streaming: true on the agent and use stream=True in the SDK for real-time token delivery
  • Add structured output: Set an outputSchema on the agent to constrain responses to a specific JSON format
  • Use the Playground: Open the Playground panel in the canvas bottom bar to test your agent interactively

See Also

On this page