This tutorial walks you through deploying a production-ready AI agent from scratch. By the end, you’ll have a working agent that can browse the web, execute code, manage files, and respond to user queries — deployed on a cloud server with monitoring.

What We’re Building

A Research Assistant Agent that:

Prerequisites

Step 1: Project Setup

mkdir ai-agent-deploy && cd ai-agent-deploy
python -m venv venv
source venv/bin/activate
pip install langchain langchain-openapi duckduckgo-search fastapi uvicorn

Step 2: Define the Agent

from langchain_openai import ChatOpenAI
from langchain.agents import create_openai_functions_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
from langchain_community.tools import DuckDuckGoSearchRun

# Use OpenRouter for multi-model access
llm = ChatOpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key="your-openrouter-key",
    model="anthropic/claude-sonnet-4"
)

# Define tools
search = DuckDuckGoSearchRun()
tools = [search]

# Define prompt
prompt = ChatPromptTemplate.from_messages([
    ("system", "You are a research assistant. Thoroughly research the given topic using web search. Provide structured, cited summaries."),
    MessagesPlaceholder("chat_history", optional=True),
    ("human", "{input}"),
    MessagesPlaceholder("agent_scratchpad"),
])

# Create agent
agent = create_openai_functions_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

Step 3: Add a Web Interface

from fastapi import FastAPI
from pydantic import BaseModel

app = FastAPI(title="Research Agent API")

class ResearchRequest(BaseModel):
    topic: str

class ResearchResponse(BaseModel):
    topic: str
    summary: str
    sources: list[str]

@app.post("/research", response_model=ResearchResponse)
async def research(request: ResearchRequest):
    result = agent_executor.invoke({"input": f"Research: {request.topic}"})
    return ResearchResponse(
        topic=request.topic,
        summary=result["output"],
        sources=[]  # Parse from agent output in production
    )

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8000)

Step 4: Deploy to Production

# On your server
git clone your-repo && cd ai-agent-deploy
python -m venv venv && source venv/bin/activate
pip install -r requirements.txt

# Create systemd service
sudo tee /etc/systemd/system/research-agent.service << EOF
[Unit]
Description=Research Agent API
After=network.target

[Service]
Type=simple
User=www-data
WorkingDirectory=/opt/ai-agent-deploy
Environment=OPENROUTER_API_KEY=your-key
ExecStart=/opt/ai-agent-deploy/venv/bin/uvicorn main:app --host 0.0.0.0 --port 8000
Restart=always

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl enable research-agent
sudo systemctl start research-agent

Step 5: Add Monitoring

# Add basic health check endpoint
@app.get("/health")
async def health():
    return {"status": "ok", "agent": "research-assistant"}

# Monitor with a simple uptime check
# Add to crontab: */5 * * * * curl -sf http://localhost:8000/health || systemctl restart research-agent

Step 6: Test It

curl -X POST http://localhost:8000/research 
  -H "Content-Type: application/json" 
  -d '{"topic": "Latest developments in AI agent frameworks 2026"}'

Production Checklist

Before going live, ensure you have:

Cost Estimate

For a small team (10 research requests/day):

Next Steps

To extend this agent:

Last updated: July 2026

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert