echo

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2026 License: MIT Imports: 4 Imported by: 0

README

Echo Provider Example

The smallest possible Glue provider. It echoes the user's most recent text back as the assistant's response.

This package is the runnable reference implementation for the Provider Plugin Guide. Copy this layout when building a new provider; replace the body of stream() with your backend code.

Test it

go test ./examples/echo-provider

Four tests cover:

  • happy-path round trip through glue.NewAgent + session.Prompt
  • compile-time assertion that *Provider satisfies glue.Provider
  • empty transcript still emits a Done event (no panic, no hang)
  • Prefix field is applied to the echoed text

No network access; nothing is gated.

Use it as a starting point

import (
    "context"

    "github.com/erain/glue"
    echo "github.com/erain/glue/examples/echo-provider"
)

agent := glue.NewAgent(glue.AgentOptions{Provider: echo.New()})
session, _ := agent.Session(context.Background(), "demo")
result, _ := session.Prompt(context.Background(), "ping")
fmt.Println(result.Text) // -> "ping"

Documentation

Overview

Package echo is a minimal example of a custom Glue provider.

It implements the glue.Provider interface by echoing the most recent user message back as the assistant's text. There is no model, no network call, and no tool support — just the smallest amount of code that satisfies the interface so a downstream package can be wired into glue.NewAgent without importing providers/gemini.

Use this as a template when adding a new production provider:

  • copy the Provider type and Provider.Stream method shape
  • replace the body of stream() with your network code
  • emit ProviderEventStart, then any number of ProviderEventTextDelta / ProviderEventThinkingDelta / ProviderEventToolCall events, then exactly one ProviderEventDone or ProviderEventError
  • remember that the channel must be closed (the loop relies on a closed channel after Done to release the receive goroutine)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// Prefix is prepended to the echoed text. Optional.
	Prefix string
}

Provider is a Glue provider that echoes the user's last text back.

func New

func New() *Provider

New constructs an echo provider.

func (*Provider) Stream

func (p *Provider) Stream(ctx context.Context, req glue.ProviderRequest) (<-chan glue.ProviderEvent, error)

Stream implements glue.Provider.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL