blades

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 19 Imported by: 0

README

Build Status GoDoc DeepWiki License

⚠️ CycleZero/blades —— 独立维护的 Go 多模态 AI Agent 框架。

主要特性方向:

  • 推理内容(reasoning_content)回传支持
  • 会话状态注入与持久化
  • 对话历史序列化/反序列化

许可证: MIT,基于 go-kratos/blades 二次开发。

Blades

Blades is a multimodal AI Agent framework for the Go language, supporting custom models, tools, memory, middleware, etc. It is suitable for multi-turn conversations, chain-of-thought reasoning, and structured output, among other use cases.

The name originates from: The game God of War, set against the backdrop of Greek mythology, tells the adventure story of Kratos transforming from a mortal into the God of War and embarking on a god-slaying rampage. The Blades are Kratos's iconic weapons.

Architecture Design

Blades leverages the characteristics of the Go language to provide a flexible and efficient AI Agent solution. Its core lies in achieving a high degree of decoupling and extensibility through unified interfaces and pluggable components. The overall architecture is as follows: architecture

  • Go Idiomatic: Built entirely according to Go's philosophy, with a code style and user experience that feel familiar to Go developers.
  • Simple to Use: Define AI Agents through concise code declarations, enabling rapid requirement delivery and making complex logic clear, easy to manage, and maintain.
  • Middleware Ecosystem: Drawing inspiration from Kratos's middleware design philosophy, features like Observability and Guardrails can be easily integrated into AI Agents.
  • Highly Extensible: Achieves a high degree of decoupling and extensibility through unified interfaces and pluggable components, facilitating the integration of different LLM models and external tools.

Core Concepts

The Blades framework realizes its powerful functionality and flexibility through a series of carefully designed core components. These components work together to build the intelligent behavior of the Agent:

  • Agent: The core unit that executes tasks, capable of invoking models and tools.
  • Prompt: Templated text used for interacting with LLMs, supporting dynamic variable substitution and complex context construction.
  • Chain: Connects multiple Agents or other Chains to form complex workflows.
  • ModelProvider: A pluggable LLM interface, allowing you to easily switch and integrate different language model services (such as OpenAI, etc.).
  • Tool: External capabilities that an Agent can use, such as calling APIs, querying databases, accessing the file system, etc.
  • Memory: Provides short-term or long-term memory capabilities for the Agent, enabling continuous conversation with context.
  • Middleware: Similar to middleware in web frameworks, it enables cross-cutting control over the Agent.

Agent

Agent is the most core interface in the Blades framework, defining the basic behavior of all executable components. Its design aims to provide a unified execution paradigm. Through the Run method, it achieves decoupling, standardization, and high composability for various functional modules within the framework. Components like Agent, Chain, and ModelProvider all implement this interface, thereby unifying their execution logic and allowing different components to be flexibly combined like Lego bricks to build complex AI Agents.

// Agent represents an autonomous agent that can process invocations and produce a sequence of messages.
type Agent interface {
    Name() string
    Description() string
    Run(context.Context, *Invocation) Generator[*Message, error]
}

ModelProvider

ModelProvider is the core abstraction layer in the Blades framework for interacting with underlying large language models (LLMs). Its design goal is to achieve decoupling and extensibility through a unified interface, separating the framework's core logic from the implementation details of specific models (such as OpenAI, DeepSeek, Gemini, etc.). It acts as an adapter, responsible for converting the framework's internal standardized requests into the format required by the model's native API and converting the model's responses back into the framework's standard format, thus enabling developers to easily switch and integrate different LLMs.

type ModelProvider interface {
    // Generate executes a complete generation request and returns the result all at once. Suitable for scenarios that do not require real-time feedback.
    Generate(context.Context, *ModelRequest, ...ModelOption) (*ModelResponse, error)
    // NewStreaming initiates a streaming request. This method immediately returns a Generator object, allowing the caller to receive the model's generated content step by step. Suitable for building real-time, typewriter-effect conversation applications.
    NewStreaming(context.Context, *ModelRequest, ...ModelOption) (Generator[*ModelResponse])
}

ModelProvider

Agent

Agent is the core coordinator in the Blades framework. As the top-level Agent, it integrates and orchestrates components such as ModelProvider, Tool, Memory, and Middleware to understand user intent and execute complex tasks. Its design allows configuration via flexible Option functions, thereby driving the behavior and capabilities of intelligent applications and fulfilling core responsibilities like task orchestration, context management, and instruction following.

Flow

flow is used to build complex workflows and multi-step reasoning. Its design philosophy involves orchestrating multiple Agent components to achieve data and control flow transfer, where the output of one Agent can serve as the input for the next. This mechanism enables developers to flexibly combine components to build highly customized AI workflows, realizing multi-step reasoning and complex data processing. It is key to implementing complex decision-making processes for Agents.

Tool

Tool is a key component for extending AI Agent capabilities, representing external functions or services that an Agent can invoke. Its design aims to empower the Agent to interact with the real world, performing specific actions or obtaining external information. Through a clear InputSchema, it guides the LLM to generate correct invocation parameters, and executes the actual logic via its internal Handle function, thereby encapsulating various external APIs, database queries, etc., into a form that the Agent can understand and invoke.

Memory

The Memory component endows AI Agents with memory capabilities, providing a universal interface for storing and retrieving conversation messages, ensuring that Agents maintain context and coherence across multiple conversation turns. Its design supports managing messages by session ID and can be configured with message count limits to balance the breadth of memory against system resource consumption. The framework provides an InMemory implementation and also encourages developers to extend it to persistent storage or more complex memory strategies.

type Memory interface {
    AddMemory(context.Context, *Memory) error
    SaveSession(context.Context, blades.Session) error
    SearchMemory(context.Context, string) ([]*Memory, error)	
}

Middleware

Middleware is a powerful mechanism for implementing cross-cutting concerns (such as logging, monitoring, authentication, rate limiting). Its design allows injecting additional behaviors into the execution flow of a Runner without modifying the Runner's core logic. It operates in a function chain form resembling an "onion model," providing highly flexible flow control and feature enhancement, thereby achieving decoupling between non-core business logic and core functionality.

💡 Quick Start

Usage Example (Chat Agent)

The following is a simple chat Agent example demonstrating how to use the OpenAI ModelProvider to build a basic conversational application:

package main

import (
    "context"
    "log"
    "os"

    "github.com/CycleZero/blades"
    "github.com/CycleZero/blades/contrib/openai"
)

func main() {
    // Configure OpenAI API key and base URL using environment variables:
    model := openai.NewModel("gpt-5", openai.Config{
        APIKey: os.Getenv("OPENAI_API_KEY"),
    })
    agent := blades.NewAgent(
        "Blades Agent",
        blades.WithModel(model),
        blades.WithInstruction("You are a helpful assistant that provides detailed and accurate information."),
    )
    // Create a Prompt with user message
    input := blades.UserMessage("What is the capital of France?")
    // Run the Agent with the Prompt
    runner := blades.NewRunner(agent)
    output, err := runner.Run(context.Background(), input)
    if err != nil {
        log.Fatal(err)
    }
    // Print the agent's response
    log.Println(output.Text())
}

Skills

Agent supports skill injection via WithSkills(...), and skills can be loaded from a directory or embed.FS. For the skill package format and metadata rules, see Agent Skill specification.

package main

import (
    "embed"

    "github.com/CycleZero/blades"
    "github.com/CycleZero/blades/skills"
)

//go:embed example-skill/*
var skillFS embed.FS

func createAgent(model blades.ModelProvider) (blades.Agent, error) {
    // Directory-based loading:
    skillsFromDir, err := skills.NewFromDir("./skills")
    if err != nil {
        return nil, err
    }
    // Embedded loading:
    skillsFromEmbed, err := skills.NewFromEmbed(skillFS)
    if err != nil {
        return nil, err
    }
    allSkills := append(skillsFromDir, skillsFromEmbed...)
    return blades.NewAgent(
        "SkillsAgent",
        blades.WithModel(model),
        blades.WithSkills(allSkills...),
    )
}

For more examples, please refer to the examples directory.

🤝 Contribution & Community

The project is currently in its early stages, and we are iterating continuously and rapidly. We sincerely invite all Go developers and AI enthusiasts to visit our GitHub repository and experience the joy of development that Blades brings firsthand.

Welcome to give the project a ⭐️ Star, explore more usage examples in the examples directory, or directly start building your first Go LLM application!

We look forward to any feedback, suggestions, and contributions from you to jointly promote the prosperity of the Go AI ecosystem.

📄 License

Blades is licensed under the MIT License. For details, please see the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNoSessionContext is returned when a session context is missing from the context.
	ErrNoSessionContext = errors.New("session not found in context")
	// ErrNoAgentContext is returned when an agent context is missing from the context.
	ErrNoAgentContext = errors.New("agent not found in context")
	// ErrMissingInvocationContext is returned when an invocation context is missing from the context.
	ErrNoInvocationContext = errors.New("invocation not found in context")
	// ErrModelProviderRequired is returned when a model provider is not supplied where required.
	ErrModelProviderRequired = errors.New("model provider is required")
	// ErrMaxIterationsExceeded is returned when an agent exceeds the maximum allowed iterations.
	ErrMaxIterationsExceeded = errors.New("maximum iterations exceeded in agent execution")
	// ErrMissingFinalResponse is returned when an agent's stream ends without a final response.
	ErrNoFinalResponse = errors.New("stream ended without a final response")
	// ErrInterrupted is returned when execution is interrupted.
	ErrInterrupted = errors.New("execution was interrupted")
	// ErrLoopEscalated is returned when a loop condition signals escalation to an outer handler.
	ErrLoopEscalated = errors.New("loop escalated to outer handler")
)
View Source
var (
	// Version is the current blades version.
	Version = buildVersion("github.com/CycleZero/blades")
)

Functions

func MergeActions

func MergeActions(base, extra map[string]any) map[string]any

MergeActions merges two action maps, with values from extra overriding those in base.

func NewAgentContext

func NewAgentContext(ctx context.Context, agent Agent) context.Context

NewAgentContext returns a new context with the given AgentContext.

func NewAgentTool

func NewAgentTool(agent Agent) tools.Tool

NewAgentTool creates a new tool that wraps the given Agent.

func NewInvocationID

func NewInvocationID() string

NewInvocationID generates a new unique invocation ID.

func NewMessageID

func NewMessageID() string

NewMessageID generates a new random message identifier.

func NewSessionContext

func NewSessionContext(ctx context.Context, session Session) context.Context

NewSessionContext returns a new Context that carries the session value.

Types

type Agent

type Agent interface {
	// Name returns the name of the agent.
	Name() string
	// Description returns a brief description of the agent's functionality.
	Description() string
	// Run processes the given invocation and returns a generator that yields messages or errors.
	Run(context.Context, *Invocation) Generator[*Message, error]
}

Agent represents an autonomous agent that can process invocations and produce a sequence of messages.

func NewAgent

func NewAgent(name string, opts ...AgentOption) (Agent, error)

NewAgent creates a new Agent with the given name and options.

type AgentContext

type AgentContext interface {
	Name() string
	Description() string
}

AgentContext provides metadata about an agent.

func FromAgentContext

func FromAgentContext(ctx context.Context) (AgentContext, bool)

FromAgentContext retrieves the AgentContext from the context, if present.

type AgentOption

type AgentOption func(*agent)

AgentOption is an option for configuring the Agent.

func WithContext

func WithContext(enabled bool) AgentOption

WithContext controls whether the Agent loads the full session history into each model call. When enabled (true), session.History is called before every model request so the model has the complete conversation context. By default (when WithContext is not used or enabled is false), only the messages produced within the current invocation are sent to the model, making the agent stateless with respect to prior turns.

func WithDescription

func WithDescription(description string) AgentOption

WithDescription sets the description for the Agent.

func WithInputSchema

func WithInputSchema(schema *jsonschema.Schema) AgentOption

WithInputSchema sets the input schema for the Agent.

func WithInstruction

func WithInstruction(instruction string) AgentOption

WithInstruction sets the instruction for the Agent.

func WithInstructionProvider

func WithInstructionProvider(p InstructionProvider) AgentOption

WithInstructionProvider sets a dynamic instruction provider for the Agent.

func WithMaxIterations

func WithMaxIterations(n int) AgentOption

WithMaxIterations sets the maximum number of iterations for the Agent. By default, it is set to 10.

func WithMiddleware

func WithMiddleware(ms ...Middleware) AgentOption

WithMiddleware sets the middleware for the Agent.

func WithModel

func WithModel(model ModelProvider) AgentOption

WithModel sets the model provider for the Agent.

func WithOutputKey

func WithOutputKey(key string) AgentOption

WithOutputKey sets the output key for storing the Agent's output in the session state.

func WithOutputSchema

func WithOutputSchema(schema *jsonschema.Schema) AgentOption

WithOutputSchema sets the output schema for the Agent.

func WithSkills

func WithSkills(skillList ...skills.Skill) AgentOption

WithSkills sets skills for the Agent.

func WithTools

func WithTools(tools ...tools.Tool) AgentOption

WithTools sets the tools for the Agent.

func WithToolsResolver

func WithToolsResolver(r tools.Resolver) AgentOption

WithToolsResolver sets a tools resolver for the Agent. The resolver can dynamically provide tools from various sources (e.g., MCP servers, plugins). Tools are resolved lazily on first use.

type ContextCompressor

type ContextCompressor interface {
	// Compress filters, truncates, or compresses messages to fit within the
	// context window. System/instruction content is handled separately via
	// ModelRequest.Instruction and is never passed to Compress.
	Compress(ctx context.Context, messages []*Message) ([]*Message, error)
}

ContextCompressor compresses, truncates, or filters the message list before each model call to keep it within the context window budget.

type DataPart

type DataPart struct {
	Name     string   `json:"name"`
	Bytes    []byte   `json:"bytes"`
	MIMEType MIMEType `json:"mimeType"`
}

DataPart is a file represented by its byte content.

type FilePart

type FilePart struct {
	Name     string   `json:"name"`
	URI      string   `json:"uri"`
	MIMEType MIMEType `json:"mimeType"`
}

FilePart is a reference to a file by its URI.

type Generator

type Generator[T, E any] = iter.Seq2[T, E]

Generator is a generic type representing a sequence generator that yields values of type T or errors of type E.

type HandleFunc

type HandleFunc func(context.Context, *Invocation) Generator[*Message, error]

HandleFunc is an adapter to allow the use of ordinary functions as Handlers.

func (HandleFunc) Handle

func (f HandleFunc) Handle(ctx context.Context, invocation *Invocation) Generator[*Message, error]

Handle implements the Handler interface for HandleFunc.

type Handler

type Handler interface {
	Handle(context.Context, *Invocation) Generator[*Message, error]
}

Handler defines a function that processes an Invocation and returns a Generator of Messages.

type InstructionProvider

type InstructionProvider func(ctx context.Context) (string, error)

InstructionProvider is a function type that generates instructions based on the given context.

type Invocation

type Invocation struct {
	ID          string
	Model       string
	Resume      bool
	Stream      bool
	Session     Session
	Instruction *Message
	Message     *Message
	// EphemeralMessages are appended to the next model request only.
	// They are not persisted into the session history.
	EphemeralMessages []*Message
	Tools             []tools.Tool
	// contains filtered or unexported fields
}

Invocation holds information about the current invocation.

func (*Invocation) Clone

func (inv *Invocation) Clone() *Invocation

Clone creates a deep copy of the Invocation. All clones share the same committed *atomic.Bool pointer. The first agent (original or any clone) to call CompareAndSwap(false, true) on it will perform the session append; all others skip. This is safe for concurrent use.

type MIMEType

type MIMEType string

MIMEType represents the media type of content.

const (
	// Text and markdown mime types.
	MIMEText     MIMEType = "text/plain"
	MIMEMarkdown MIMEType = "text/markdown"
	// Common image mime types.
	MIMEImagePNG  MIMEType = "image/png"
	MIMEImageJPEG MIMEType = "image/jpeg"
	MIMEImageWEBP MIMEType = "image/webp"
	// Common audio mime types (non-exhaustive).
	MIMEAudioWAV  MIMEType = "audio/wav"
	MIMEAudioMP3  MIMEType = "audio/mpeg"
	MIMEAudioOGG  MIMEType = "audio/ogg"
	MIMEAudioAAC  MIMEType = "audio/aac"
	MIMEAudioFLAC MIMEType = "audio/flac"
	MIMEAudioOpus MIMEType = "audio/opus"
	MIMEAudioPCM  MIMEType = "audio/pcm"
	// Common video mime types (non-exhaustive).
	MIMEVideoMP4 MIMEType = "video/mp4"
	MIMEVideoOGG MIMEType = "video/ogg"
)

func (MIMEType) Format

func (m MIMEType) Format() string

Format returns the file format associated with the MIMEType.

func (MIMEType) Type

func (m MIMEType) Type() string

Type returns the general type of the MIMEType (e.g., "image", "audio", "video", or "file").

type Message

type Message struct {
	ID           string         `json:"id"`
	Role         Role           `json:"role"`
	Parts        []Part         `json:"parts"`
	Author       string         `json:"author"`
	InvocationID string         `json:"invocationId,omitempty"`
	Status       Status         `json:"status"`
	FinishReason string         `json:"finishReason,omitempty"`
	TokenUsage   TokenUsage     `json:"tokenUsage,omitempty"`
	Actions      map[string]any `json:"actions,omitempty"`
	Metadata     map[string]any `json:"metadata,omitempty"`
}

Message represents a single message in a conversation.

func AppendMessages

func AppendMessages(base []*Message, extra ...*Message) []*Message

AppendMessages appends extra messages to base, replacing any messages in base that have matching IDs in extra.

func AssistantMessage

func AssistantMessage(parts ...any) *Message

AssistantMessage creates an assistant-authored message from parts.

func MergeParts

func MergeParts(base, extra *Message) *Message

MergeParts merges the Parts of two messages, mutating and returning base. If base is nil, extra is returned. If extra is nil, base is returned.

func NewAssistantMessage

func NewAssistantMessage(status Status) *Message

NewAssistantMessage creates a new assistant message with the given status.

func SystemMessage

func SystemMessage(parts ...any) *Message

SystemMessage creates a system-authored message from parts.

func UserMessage

func UserMessage(parts ...any) *Message

UserMessage creates a user-authored message from parts.

func (*Message) Clone

func (m *Message) Clone() *Message

Clone creates a deep copy of the message.

func (*Message) Data

func (m *Message) Data() *DataPart

Data returns the first data part of the message, or nil if none exists.

func (*Message) File

func (m *Message) File() *FilePart

File returns the first file part of the message, or nil if none exists.

func (*Message) MarshalJSON

func (m *Message) MarshalJSON() ([]byte, error)

MarshalJSON encodes the message, tagging each part with its concrete type so the parts can be restored by UnmarshalJSON.

func (*Message) Reasoning

func (m *Message) Reasoning() string

Reasoning returns the concatenated reasoning / chain-of-thought content of the message, or an empty string if the model produced none.

func (*Message) String

func (m *Message) String() string

func (*Message) Text

func (m *Message) Text() string

Text returns the first text part of the message, or an empty string if none exists.

func (*Message) UnmarshalJSON

func (m *Message) UnmarshalJSON(data []byte) error

UnmarshalJSON decodes a message previously produced by MarshalJSON, restoring each Part from its type tag.

type Middleware

type Middleware func(Handler) Handler

Middleware wraps a Handler and returns a new Handler with additional behavior. It is applied in a chain (outermost first) using ChainMiddlewares.

func ChainMiddlewares

func ChainMiddlewares(mws ...Middleware) Middleware

ChainMiddlewares composes middlewares into one, applying them in order. The first middleware becomes the outermost wrapper.

type ModelProvider

type ModelProvider interface {
	// Name returns the model name.
	Name() string
	// Generate executes the request and returns a single assistant response.
	Generate(context.Context, *ModelRequest) (*ModelResponse, error)
	// NewStreaming executes the request and returns a stream of assistant responses.
	NewStreaming(context.Context, *ModelRequest) Generator[*ModelResponse, error]
}

ModelProvider is an interface for multimodal chat-style models.

type ModelRequest

type ModelRequest struct {
	Tools        []tools.Tool       `json:"tools,omitempty"`
	Messages     []*Message         `json:"messages"`
	Instruction  *Message           `json:"instruction,omitempty"`
	InputSchema  *jsonschema.Schema `json:"inputSchema,omitempty"`
	OutputSchema *jsonschema.Schema `json:"outputSchema,omitempty"`
}

ModelRequest is a multimodal chat-style request to the provider.

type ModelResponse

type ModelResponse struct {
	Message *Message `json:"message"`
}

ModelResponse is a single assistant message as a result of generation.

type Part

type Part interface {
	// contains filtered or unexported methods
}

Part is a part of a message, which can be text or a file.

func NewMessageParts

func NewMessageParts(inputs ...any) []Part

NewMessageParts converts a heterogeneous list of content inputs into model parts. Accepts raw string, Text, FileURI, and FileBytes.

type ReasoningPart

type ReasoningPart struct {
	Text string `json:"text"`
}

ReasoningPart is the model's reasoning / chain-of-thought content. It is surfaced to callers for observability but is deliberately excluded from Message.Text(), so it never becomes part of the answer and is never echoed back to the model on subsequent turns.

type Role

type Role string

Role indicates the author of a message in a conversation.

const (
	// RoleUser is an end user.
	RoleUser Role = "user"
	// RoleSystem provides system-level instructions.
	RoleSystem Role = "system"
	// RoleAssistant is the model output.
	RoleAssistant Role = "assistant"
	// RoleTool indicates a message generated by a tool.
	RoleTool Role = "tool"
)

type RunOption

type RunOption func(*RunOptions)

RunOption defines options for configuring the Runner.

func WithInvocationID

func WithInvocationID(invocationID string) RunOption

WithInvocationID sets a custom invocation ID for the Runner.

func WithResume

func WithResume(resume bool) RunOption

WithResume indicates whether to resume from the last session state.

func WithSession

func WithSession(session Session) RunOption

WithSession sets a custom session for the Runner.

type RunOptions

type RunOptions struct {
	Session      Session
	Resume       bool
	InvocationID string
}

RunOptions holds configuration options for running the agent.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner is responsible for executing a Runnable agent within a session context.

func NewRunner

func NewRunner(rootAgent Agent, opts ...RunnerOption) *Runner

NewRunner creates a new Runner with the given agent and options.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, message *Message, opts ...RunOption) (*Message, error)

Run executes the agent with the provided prompt and options within the session context.

func (*Runner) RunStream

func (r *Runner) RunStream(ctx context.Context, message *Message, opts ...RunOption) Generator[*Message, error]

RunStream executes the agent in a streaming manner, yielding messages as they are produced.

type RunnerOption

type RunnerOption func(*Runner)

RunnerOption configures a Runner at construction time.

type Session

type Session interface {
	ID() string
	State() State
	SetState(string, any)
	Append(context.Context, *Message) error
	// History returns the message history prepared for the next model call.
	// When a ContextCompressor is configured, the history is compressed before
	// being returned; otherwise the raw message list is returned unchanged.
	History(ctx context.Context) ([]*Message, error)
}

Session holds the state of a flow along with a unique session ID.

func EnsureSession

func EnsureSession(ctx context.Context) Session

EnsureSession returns the Session stored in ctx, or a new in-memory Session if none is present.

func NewSession

func NewSession(opts ...SessionOption) Session

NewSession creates a new Session instance with an auto-generated UUID. Pass SessionOption values to configure the session (e.g. WithContextCompressor). Legacy map arguments are still accepted for backwards compatibility.

func SessionFromContext

func SessionFromContext(ctx context.Context) (Session, bool)

SessionFromContext retrieves the SessionContext from the context.

type SessionOption

type SessionOption func(*sessionInMemory)

SessionOption configures a Session at construction time.

func WithContextCompressor

func WithContextCompressor(c ContextCompressor) SessionOption

WithContextCompressor sets the ContextCompressor used by Session.History to compress the message history before returning it for each model call.

type State

type State map[string]any

State holds arbitrary key-value pairs representing the state.

func (State) Clone

func (s State) Clone() State

Clone creates a deep copy of the State.

type Status

type Status string

Status indicates the state of a message.

const (
	// StatusInProgress indicates the message is being generated.
	StatusInProgress Status = "in_progress"
	// StatusIncomplete indicates the message is partially generated.
	StatusIncomplete Status = "incomplete"
	// StatusCompleted indicates the message is fully generated.
	StatusCompleted Status = "completed"
)

type TextPart

type TextPart struct {
	Text string `json:"text"`
}

TextPart is plain text content.

type TokenCounter

type TokenCounter interface {
	Count(messages ...*Message) int64
}

TokenCounter estimates the number of tokens for a set of messages. Implementations may use model-specific tokenizers for precise counting, or rely on heuristic approximations.

type TokenUsage

type TokenUsage struct {
	InputTokens  int64 `json:"inputTokens"`
	OutputTokens int64 `json:"outputTokens"`
	TotalTokens  int64 `json:"totalTokens"`
}

TokenUsage tracks token consumption for a message.

type ToolContext

type ToolContext = tools.ToolContext

ToolContext is an alias for tools.ToolContext so that existing callers of blades.ToolContext / blades.FromToolContext continue to work unchanged.

type ToolPart

type ToolPart struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Request   string `json:"arguments"`
	Response  string `json:"result,omitempty"`
	Completed bool   `json:"completed,omitempty"`
}

ToolPart is a tool call, containing its request, response, and completion state.

func NewToolPart

func NewToolPart(id, name, request string) ToolPart

NewToolPart creates a tool call part that has not completed yet.

Directories

Path Synopsis
context
contrib
openai module
internal
Package recipe provides a declarative YAML-based system for defining and building blades.Agent workflows.
Package recipe provides a declarative YAML-based system for defining and building blades.Agent workflows.

Jump to

Keyboard shortcuts

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