tRPC-Agent-Go · build a streaming, tool-calling AI agent in Go

4 months ago

Almost every agent framework is written in Python. tRPC-Agent-Go brings production agents to Go instead: concurrent, observable, and shipped as a single binary. It comes from Tencent's tRPC open source group, and runs in production behind apps like Tencent Yuanbao and Tencent Video. The whole thing is five composable layers. Let's build one.

Ask about this presentation

Chapters

  1. 0:00Slide 1
  2. 0:18Five composable layers
  3. 0:34A model, then any Go function as a tool
  4. 0:55Wrap it in an agent, run it with a runner
  5. 1:07Run it: a channel of streaming events
  6. 1:21Try it in three commands
  7. 1:36One agent today, a whole stack tomorrow
Show transcript
  1. Almost every agent framework is written in Python. tRPC-Agent-Go brings production agents to Go instead: concurrent, observable, and shipped as a single binary. It comes from Tencent's tRPC open source group, and runs in production behind apps like Tencent Yuanbao and Tencent Video. The whole thing is five composable layers. Let's build one.

    Slide text
    tRPC-Agent-Go logo

    A Go framework for building production agent systems.

    Model → Tool → Agent → Runner → events
  2. Here is the shape. A model gives you the language reasoning. Tools are things the agent can call. An agent wraps the model and its tools. A runner executes that agent and manages the session. And you get back a stream of events. Every piece is pluggable, and they talk to each other through events.

    Slide text
    tRPC-Agent-Go component architecture

    A model, the tools it can call, an agent that wraps them, a runner that executes · every piece pluggable, wired by events.

  3. Start with a model. Point it at OpenAI, DeepSeek, or another provider through a variant. Then the good part: any Go function becomes a tool. You wrap a plain function, give it a name and a description, and that is it. The function takes a typed request struct, and its schema tags become the tool's parameter schema. No glue code to write by hand.

    Slide text
    modelInstance := openai.New("deepseek-chat",
        openai.WithVariant(openai.VariantDeepSeek))
    
    calculatorTool := function.NewFunctionTool(
        calculator,
        function.WithName("calculator"),
        function.WithDescription("add, sub, ..."))
    // any Go func becomes an LLM tool
    func calculator(ctx context.Context,
        req calculatorReq) (calculatorRsp, error)
    
    type calculatorReq struct {
        A  float64 `jsonschema:"required"`
        Op string  `jsonschema:"enum=add,enum=sub"`
    }

    The struct's schema tags become the tool's parameter schema · no glue code.

  4. Now wrap them. The agent takes your model, your tools, and a config that turns on streaming. Then a runner wraps the agent. The runner is what manages sessions and drives the execution flow, so you do not hand roll any of that.

    Slide text
    agent := llmagent.New("assistant",
        llmagent.WithModel(modelInstance),
        llmagent.WithTools(
            []tool.Tool{calculatorTool}),
        llmagent.WithGenerationConfig(
            model.GenerationConfig{Stream: true}),
    )
    runner := runner.NewRunner(
        "calculator-app", agent)

    The runner manages sessions and execution flow for you.

  5. Run it, and you get back a Go channel of events. Range over the channel and print each streamed chunk as it arrives. It feels like idiomatic Go, because it is. Want to stop a run early? Cancel the context. There is no special stop method to learn.

    Slide text
    events, err := runner.Run(ctx,
        "user-001", "session-001",
        model.NewUserMessage("Calculate what 2+3 equals"))
    
    for event := range events {
        if event.Object == "chat.completion.chunk" {
            fmt.Print(event.Response.
                Choices[0].Delta.Content)
        }
    }

    Idiomatic Go · to stop a run, just cancel the context · no special stop method.

  6. You can try all of this in about a minute. Clone the repo, set your API key, and run the example. You land in an interactive, streaming chat with a calculator and a time tool wired up. Ask it something, and watch the agent plan, call a tool, and stream the answer back.

    Slide text
    # 1 · clone and enter
    git clone https://github.com/trpc-group/trpc-agent-go.git
    cd trpc-agent-go
    # 2 · set your key
    export OPENAI_API_KEY="your-api-key-here"
    # 3 · run the example
    cd examples/runner
    go run . -model="gpt-4o-mini" -streaming=true
    A tRPC-Agent-Go agent streaming events to an AG-UI client
  7. That is one agent. From here it scales: multi-agent workflows in chain, parallel, cycle, and graph forms, long-term memory, retrieval, agent skills, evaluation, and full tracing, all native to Go. It is Apache 2.0. Explore the rest of these docs to go deeper.

    Slide text
    • Multi-agent · Chain, Parallel, Cycle, and Graph workflows.
    • Memory + Knowledge · sessions, long-term memory, retrieval.
    • Skills & Evolution · reusable workflows, self-improvement.
    • Observability · OpenTelemetry tracing and evaluation.

    go get trpc.group/trpc-go/trpc-agent-go  ·  Apache-2.0

What happened in AI today, in your inbox

One short email each evening. Read it and you’re caught up.

Built with ❤️ in New York