Skip to main content
Here an agent framework does the thinking. LangGraph’s ReAct agent runs inside the actor’s process() method — with tool calling, multi-step reasoning, the works — while the Agent SDK supplies what the framework doesn’t have: durable per-customer history, retries, and the follow-up timer. this.messages.toLangChain() returns plain { role, content } messages, which LangGraph accepts as-is. The LLM is ChatOpenAI pointed at Telnyx Inference — swap baseURL, key, and model to bring any OpenAI-compatible provider. The same pattern fits any agent framework that runs on Node. Install the framework alongside the runtime:
src/conversation.ts — the actor:
Only the framework’s final reply lands in this.messages — intermediate tool calls and tool results stay inside the LangGraph run. If you want them in the durable history too, append() them from out.messages. src/index.ts — the function that routes inbound webhooks to the right actor:
Verify Telnyx webhook signatures before processing — see receiving webhooks. The examples above omit verification for brevity; production code must check the telnyx-signature-ed25519 header.
telnyx.toml:
Set the API key as a secret — it reaches the actor as process.env.TELNYX_API_KEY:
Prefer owning the loop yourself? The hand-rolled version of this same agent needs no key at all — it calls inference through the pre-authenticated Telnyx binding. A framework owns its own HTTP stack, so it authenticates like any external client.
Task delivery is at-least-once: a crash after messages.add() or messages.send() succeeds retries the whole process() method. For production, guard outbound side effects — e.g. check state before sending, or use a stable message ID to deduplicate.