DEV Community

Serhii Antonuik
Serhii Antonuik

Posted on Originally published at uagents8.com

Deploy a LangGraph agent to a public URL

You have a LangGraph graph that works in a notebook. Now someone else needs to call it: a teammate, a Telegram bot, a CRM that posts a question and waits for an answer. That means a web API, a server that stays up, pinned dependencies, a secret for your model key, and a URL that not everyone on the internet can spend your model budget through.

This walkthrough takes a small LangGraph agent from a folder on your laptop to a public HTTPS address on uagents8, then locks that address with a token. In our run on 28 October 2026 the agent was live 78 seconds after we created it; the build took about 38 of them.

What we're deploying

One graph, two nodes, one branch:

START --(the question is arithmetic)--> calculate --> END
START --(anything else)--------------> respond   --> END
Enter fullscreen mode Exit fullscreen mode

calculate is a tool node in plain Python. respond is where your model goes; until you add one, it answers with a labelled stub, so the whole thing runs with no key and no network. The graph sits behind FastAPI with one route that matters, POST /ask.

import ast
import operator
import os
from typing import TypedDict

import uvicorn
from fastapi import FastAPI
from langgraph.graph import END, START, StateGraph
from pydantic import BaseModel, Field


class State(TypedDict):
    question: str
    answer: str
    mode: str  # "tool", "stub" or "model"


_OPERATORS = {ast.Add: operator.add, ast.Sub: operator.sub, ast.Mult: operator.mul, ast.Div: operator.truediv}


def _evaluate(node: ast.AST) -> float:
    """Evaluate + - * / and parentheses on numbers; anything else raises ValueError."""
    if isinstance(node, ast.Expression):
        return _evaluate(node.body)
    if isinstance(node, ast.Constant) and isinstance(node.value, (int, float)):
        return node.value
    if isinstance(node, ast.UnaryOp) and isinstance(node.op, ast.USub):
        return -_evaluate(node.operand)
    if isinstance(node, ast.BinOp) and type(node.op) in _OPERATORS:
        return _OPERATORS[type(node.op)](_evaluate(node.left), _evaluate(node.right))
    raise ValueError("unsupported expression")


def _arithmetic(question: str) -> str | None:
    """The expression inside `question`, if the whole question is just arithmetic."""
    expression = question.strip().lower().removeprefix("what is").strip().rstrip("?= ")
    if not expression or not any(ch.isdigit() for ch in expression):
        return None
    if any(ch not in "0123456789+-*/(). " for ch in expression):
        return None
    return expression


def route(state: State) -> str:
    return "calculate" if _arithmetic(state["question"]) else "respond"


def calculate(state: State) -> dict:
    expression = _arithmetic(state["question"]) or ""
    try:
        result = _evaluate(ast.parse(expression, mode="eval"))
    except (SyntaxError, ValueError, ArithmeticError):
        return {"answer": f"I could not calculate {expression!r}.", "mode": "tool"}
    return {"answer": f"{expression} = {result:g}", "mode": "tool"}


def respond(state: State) -> dict:
    # Your model call goes here. The key comes from the environment, never from this file.
    return {"answer": f"[stub] You asked: {state['question']}", "mode": "stub"}


builder = StateGraph(State)
builder.add_node("calculate", calculate)
builder.add_node("respond", respond)
builder.add_conditional_edges(START, route, {"calculate": "calculate", "respond": "respond"})
builder.add_edge("calculate", END)
builder.add_edge("respond", END)
graph = builder.compile()

app = FastAPI()


class Ask(BaseModel):
    question: str = Field(min_length=1, max_length=500)


@app.post("/ask")
def ask(body: Ask) -> dict:
    result = graph.invoke({"question": body.question, "answer": "", "mode": ""})
    return {"question": body.question, "answer": result["answer"], "mode": result["mode"]}


if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=int(os.environ.get("PORT", "8000")))
Enter fullscreen mode Exit fullscreen mode

_arithmetic and _evaluate accept + - * / and parentheses on numbers and nothing else, so user input never reaches eval. A malformed expression gets a polite answer, not a crash.

Three things the platform needs from your code

1. Listen on PORT, on 0.0.0.0. The last two lines do it. The platform sets PORT; a server bound to 127.0.0.1 runs fine and can never be reached.

2. Start listening before anything slow. The health check only asks whether the port accepts connections. It requests no route, so an API with only /ask is fine. It gives the port about 150 seconds to open. Load big models or indexes after the server is up, or lazily on the first request.

3. Pin every dependency. The build runs Python 3.12 with no compiler, so pick versions that ship wheels. In a clean virtual environment:

pip install fastapi uvicorn langgraph
pip freeze > requirements.txt
Enter fullscreen mode Exit fullscreen mode

The sample pins fastapi==0.143.3, uvicorn==0.54.0 and langgraph==1.2.16. main.py and requirements.txt sit at the top level, and the platform runs python main.py. There is no build file to write: the platform works out the build from your code, and if your project already has its own build file at the top level, it uses that as written.

Deploy it

Push the folder to a GitHub, GitLab or Bitbucket repository, or zip main.py and requirements.txt.

In the dashboard, press + Deploy Agent:

  1. Source: pick your Git provider and the repository. Every push to the branch redeploys. Or pick Code Archive and upload the zip.
  2. Configure: keep Continuous Service and choose a Resource size. Sizes are memory limits: T is 256 MB, S 512 MB, L 1 GB. In our run this agent used about 80 MB, so T is enough.
  3. Confirm, then Deploy agent.

The Configure step of the deploy wizard with the three resource sizes, T, S and L, highlighted

The status screen moves from Building agent to Starting your agent to Running. Ours took 78 seconds, uploaded as a zip, with no model key. The agent's page then shows its public URL.

The page of a running agent on the demo account, with its Running status and the Open agent button highlighted

Call it

curl -X POST https://<your-agent-url>/ask \
  -H "Content-Type: application/json" \
  -d '{"question": "what is 2+3*4?"}'
Enter fullscreen mode Exit fullscreen mode
{"question": "what is 2+3*4?", "answer": "2+3*4 = 14", "mode": "tool"}
Enter fullscreen mode Exit fullscreen mode

Ask it anything else and you get the stub, with "mode": "stub". That's your sign that the branch to the model is wired and waiting.

Add your model

Put your provider's client library in requirements.txt (pinned) and replace the body of respond() with the call. Then add the key in the agent's Settings → Environment Variables, with Sensitive switched on, and redeploy. A changed variable is picked up on the next deploy. The key never goes into the code or the repository.

Close the door: an access token

Here is the part most tutorials skip. Your agent now has a public URL, and behind it sits a model you pay for per token. Anyone who finds the URL can spend your budget.

Open the agent's Settings tab, find Access tokens and choose Generate agent token. Give it a name you'll recognise (crm, telegram-bot) and pick how long it stays valid: 7, 30 or 90 days, or no expiry. Copy it. It starts with uagt_live_ and is shown only once.

The Generate agent token dialog: a name for the caller and how long the token stays valid

curl -X POST https://<your-agent-url>/ask \
  -H "Authorization: Bearer uagt_live_..." \
  -H "Content-Type: application/json" \
  -d '{"question": "what is 6*7?"}'
Enter fullscreen mode Exit fullscreen mode

A call without a valid token gets 401 Unauthorized before it reaches your code or your model. Once an agent has its first token, every caller needs one, so give your existing callers theirs before you generate it. One token per caller means you can revoke a leaked one without breaking the others.

The Access tokens card of an agent with two active tokens, one per caller, each with its own Revoke button

When the deploy fails

It will, sooner or later: a package you installed locally and never pinned, a variable you renamed in one file and not the other, a server bound to localhost. The failed agent's page explains the error in plain language. If you press Fix with AI, it reads the error and your code, patches a copy, checks the patch before building it, and deploys the fixed copy as a new version. If that copy fails too, it makes one more attempt. Your repository is never changed, and you can restore the previous version in one click.

What it costs

Size T runs on every plan, from Builder at €19 a month (prices before VAT). Monthly plans start with a 14-day free trial of every feature. A card is required to prevent abuse, and nothing is charged unless you choose a plan to continue with. For the launch, LAUNCH30 takes 30% off the first three months on Builder or Growth, monthly billing, until 30 November; with the trial, the discount starts with your first payment, after the trial. Code from your laptop to a token-protected URL, in Europe.

Try it: https://uagents8.com/?utm_source=devto&utm_medium=referral&utm_campaign=launch-2026-11&utm_content=devto-langgraph-article

Top comments (0)