Skip to content

Build AI agents atomically. Atomic Agents re-implementation with Golang

License

Notifications You must be signed in to change notification settings

bububa/atomic-agents

Repository files navigation

Atomic Agents Golang version

Go Reference Go goreleaser GitHub go.mod Go version of a Go module GoReportCard GitHub license GitHub release

Building AI agents, atomically. This is an implementation for Atomic Agents in Golang.

The Atomic Agents framework is designed around the concept of atomicity to be an extremely lightweight and modular framework for building Agentic AI pipelines and applications without sacrificing developer experience and maintainability. The framework provides a set of tools and agents that can be combined to create powerful applications. It is built on top of instructor and leverages the power of jsonschema for data and schema validation and serialization. All logic and control flows are written in Golang, enabling developers to apply familiar best practices and workflows from traditional software development without compromising flexibility or clarity.

Anatomy of an Agent

In Atomic Agents, an agent is composed of several key components:

  • System Prompt: Defines the agent's behavior and purpose.
  • Input Schema: Specifies the structure and validation rules for the agent's input.
  • Output Schema: Specifies the structure and validation rules for the agent's output.
  • Memory: Stores conversation history or other relevant data.
  • Context Providers: Inject dynamic context into the agent's system prompt at runtime.

Here's a high-level architecture diagram:

High-level architecture overview of Atomic Agents

Diagram showing what is sent to the LLM in the prompt

For more details please read from the original website.

Why reinvent wheel

  • don't like python
  • easy integrate into exists Golang projects
  • better performance

Installation

go get -u github.com/bububa/atomic-agents

Project Structure

Atomic Agents with the following main components:

  1. agents/: The core Atomic Agents library
  2. components/: The Atomic Agents components contains Message, Memory, SystemPromptGenerator, SystemPromptContextProvider utilities
  3. schema/: Defines the Input/Output schema structures and interfaces
  4. examples/: Example projects showcasing Atomic Agents usage
  5. tools/: A collection of tools that can be used with Atomic Agents

Quickstart & Examples

A complete list of examples can be found in the examples directory.

Here's a quick snippet demonstrating how easy it is to create a powerful agent with Atomic Agents:

package main

import (
	"context"
	"fmt"

	"github.com/bububa/atomic-agents/agents"
	"github.com/bububa/atomic-agents/components"
	"github.com/bububa/atomic-agents/schema"
)

func main() {
	ctx := context.Background()
	mem := components.NewMemory(10)
	initMsg := mem.NewMessage(components.AssistantRole, schema.CreateOutput("Hello! How can I assist you today?"))
	agent := agents.NewAgent[schema.Input, schema.Output](
		agents.WithClient(newInstructor()),
		agents.WithMemory(mem),
		agents.WithModel("gpt-4o-mini"),
		agents.WithTemperature(0.5),
		agents.WithMaxTokens(1000))
	output := schema.NewOutput("")
	input := schema.NewInput("Today is 2024-01-01, only response with the date without any other words")
	if err := agent.Run(ctx, input, output); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Println(agent.SystemPrompt())
	fmt.Println("")
	fmt.Printf("Agent: %s\n", initMsg.Content().(schema.Output).ChatMessage)
	fmt.Printf("User: %s\n", input.ChatMessage)
	fmt.Printf("Agent: %s\n", output.ChatMessage)
	// Output:
	// # IDENTITY and PURPOSE
	// - This is a conversation with a helpful and friendly AI assistant.
	//
	// # OUTPUT INSTRUCTIONS
	// - Always respond using the proper JSON schema.
	// - Always use the available additional information and context to enhance the response.
	//
	// Agent: Hello! How can I assist you today?
	// User: Today is 2024-01-01, only response with the date without any other words
	// Agent: 2024-01-01
}

License

This project is licensed under the MIT License—see the LICENSE file for details.

About

Build AI agents atomically. Atomic Agents re-implementation with Golang

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages