Skip to main content
Any turn taking runs on the Agent class, whether a framework or a loop the user writes. Glue code joins the two. The class keeps the conversation, and the turn taking produces each reply.

Write the Glue

  • receive records the message in the log and returns, inside the 30-second budget of an inbound call.
  • queue runs process as a task, which has minutes, retries on failure and survives restarts.
  • process reads the history in the shape the turn taking expects and records the reply, so the next turn sees it.
takeTurn is the slot. The log reads the history out in three shapes for it, toOpenAI(), toAnthropic() and toLangChain(). Under the entry deploy generates, a text or an email reaches the class’s receiveVia(text, from, key, via), so a class wired to channels implements that method, and receive is the RPC door. A client reaches it once the method is marked with @rpc() and authorize grants the client the rpc claim.

Write the Loop by Hand

The smallest turn taking is one model call. The Telnyx inference endpoint is reached through the TELNYX binding on env with the account’s credential, so the loop holds no key.
Env types no bindings, so the class adds TELNYX, and the history and the response are cast, as managed/model.ts does. A loop with tools calls the model again after each tool result. It records the call and the result with append(), and toOpenAI() returns them to the model on the next read.

Plug In a Framework

A framework takes the same place. LangGraph reads the toLangChain() history as it is.
  • A framework makes its own HTTP calls, so it authenticates like any client. Its key reaches the class as an environment variable.
  • Only the final reply reaches the log. The tool calls inside the run stay with the framework, and append() records them when a later turn needs them.
The Agent Harness SDK is Telnyx’s own turn taking, and it takes the same place. createHarness() builds it inside the class.