bubo

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2025 License: MIT Imports: 16 Imported by: 0

README

🦉 Bubo: A Framework for Building AI Agents

Bubo is a Go framework for creating and orchestrating AI agents, with first-class support for OpenAI's GPT models and function calling capabilities.

🌟 Overview

Bubo provides a robust foundation for building AI agents that can:

  • Execute tools and functions with parallel execution support
  • Handle streaming responses from LLM providers
  • Process multi-modal inputs (text, images, audio)
  • Manage complex conversation threads
  • Maintain short-term memory for context
  • Support event-driven architectures

🏗 Project Structure

  • api/ - Core API definitions and agent-related functionality
  • events/ - Event system for hooks and message handling
  • messages/ - Message types and content handling
  • provider/ - LLM provider integrations (OpenAI, etc.)``
  • tool/ - Tool system implementation
  • internal/
    • broker/ - Message broker implementation
    • executor/ - Tool execution engine
    • shorttermmemory/ - Context management and memory
  • examples/ - Example implementations and usage patterns

✨ Key Features

  • 🛠 Flexible Agent System

    • Define custom agents with specific tools and capabilities
    • Configure model parameters and instructions
    • Support for parallel tool execution
    • Short-term memory for maintaining context
  • 🔌 Provider Integration

    • First-class support for OpenAI's chat models
    • Extensible provider system for other LLMs
    • Streaming support for real-time responses
    • Function calling capabilities
    • Multi-modal content handling (text, images, audio)
  • 📝 Rich Message Handling

    • Support for various message types (user, assistant, tool calls)
    • Structured content parts for different media types
    • Thread management for complex conversations
    • Event-driven message processing
  • 🔧 Tool System

    • Define custom tools with JSON schema validation
    • Support for parallel tool execution
    • Structured tool responses and error handling
    • Tool generation utilities
  • 📊 Observability

    • Event hooks for system monitoring
    • Stream events for real-time monitoring
    • Error tracking and handling

🚀 Getting Started

package main

import (
  "context"
  "log/slog"
  "os"
  "time"

  // Ensure API Key is loaded
  _ "github.com/joho/godotenv/autoload"

  "github.com/casualjim/bubo"
  "github.com/casualjim/bubo/api"
  "github.com/casualjim/bubo/examples/internal/msgfmt"
  "github.com/casualjim/bubo/agent"
  "github.com/casualjim/bubo/provider/openai"
)

var (
  englishAgent = agent.New(
    agent.Name("English Agent"),
    agent.Model(openai.GPT4oMini()),
    agent.Instructions("You only speak English, so you only reply in english."),
    agent.Tools(transferToSpanishAgentTool),
  )
  spanishAgent = agent.New(
    agent.Name("Spanish Agent"),
    agent.Model(openai.GPT4oMini()),
    agent.Instructions("You only speak Spanish, so you only reply in spanish."),
  )
)

// Transfer spanish speaking users immediately
//
// bubo:agentTool
func transferToSpanishAgent() api.Agent { return spanishAgent }

func main() {
  slog.Info("running basic/agent-handoff example")
  ctx := context.Background()

  hook, result := msgfmt.Console[string](ctx, os.Stdout)

  p := bubo.New(
    bubo.Agents(englishAgent),
    bubo.Steps(
      bubo.Step(englishAgent.Name(), "Hola. ¿Como estás?"),
    ),
  )

  if err := p.Run(ctx, bubo.Local(hook)); err != nil {
    slog.Error("error running agent", "error", err)
    return
  }

  <-result
}

We include a code generation tool to convert the go function into an agent function:

go run github.com/casualjim/bubo/cmd/bubo-tool-gen@latest

📦 Installation

go get github.com/casualjim/bubo
Code generation
go install github.com/casualjim/bubo/cmd/bubo-tool-gen@latest

🛠 Requirements

  • Go 1.21 or higher
  • OpenAI API key (for OpenAI provider)

📝 License

This project is licensed under the terms specified in the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	WithContextVars = opts.ForName[ExecutionContext, types.ContextVars]("contextVars")
	Streaming       = opts.ForName[ExecutionContext, bool]("stream")
	WithMaxTurns    = opts.ForName[ExecutionContext, int]("maxTurns")
)
View Source
var Name = opts.ForName[Knot, string]("name")

Functions

func Agents added in v0.1.3

func Agents(agent api.Agent, extraAgents ...api.Agent) opts.Option[Knot]

func Steps added in v0.1.0

func Steps(step ConversationStep, extraSteps ...ConversationStep) opts.Option[Knot]

func StructuredOutput added in v0.1.1

func StructuredOutput[T any](name, description string) opts.Option[ExecutionContext]

Types

type ConversationStep added in v0.1.0

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

func Step added in v0.1.0

func Step[T Task](agentName string, tsk T) ConversationStep

type ExecutionContext added in v0.1.0

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

func Local added in v0.1.0

func Local[T any](hook Hook[T], options ...opts.Option[ExecutionContext]) ExecutionContext

type Future added in v0.1.0

type Future[T any] interface {
	Get() (T, error)
}

type Hook added in v0.1.0

type Hook[T any] interface {
	events.Hook
	OnResult(context.Context, T)
	OnClose(context.Context)
}

type Knot added in v0.1.3

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

func New added in v0.1.0

func New(options ...opts.Option[Knot]) *Knot

func (*Knot) Run added in v0.1.3

func (p *Knot) Run(ctx context.Context, rc ExecutionContext) error

type Task added in v0.1.3

type Task interface {
	~string | messages.Message[messages.UserMessage]
}

Directories

Path Synopsis
cmd
bubo-tool-gen command
Package events provides a pub/sub event system for AI agent interactions, supporting type-safe event handling with rich metadata and serialization.
Package events provides a pub/sub event system for AI agent interactions, supporting type-safe event handling with rich metadata and serialization.
examples
basic/minimal command
triage command
internal
broker
Package broker implements a pub/sub message broker for distributing events between AI agents, tools, and other system components.
Package broker implements a pub/sub message broker for distributing events between AI agents, tools, and other system components.
executor
Package executor provides the core execution engine for AI agent operations, implementing a robust system for running commands with support for streaming, tool calls, and asynchronous operations through a Future/Promise pattern.
Package executor provides the core execution engine for AI agent operations, implementing a robust system for running commands with support for streaming, tool calls, and asynchronous operations through a Future/Promise pattern.
shorttermmemory
Package shorttermmemory provides functionality for managing the runtime state of message processing, including message aggregation, forking, and joining of message streams, as well as usage tracking.
Package shorttermmemory provides functionality for managing the runtime state of message processing, including message aggregation, forking, and joining of message streams, as well as usage tracking.
Package messages provides types and functionality for handling multi-part message content in different formats including text, images, and audio.
Package messages provides types and functionality for handling multi-part message content in different formats including text, images, and audio.
pkg
Package provider implements an abstraction layer for interacting with AI model providers (like OpenAI, Anthropic, etc.) in a consistent way.
Package provider implements an abstraction layer for interacting with AI model providers (like OpenAI, Anthropic, etc.) in a consistent way.

Jump to

Keyboard shortcuts

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