Skip to content

Latest commit

 

History

History
49 lines (33 loc) · 1.58 KB

CLAUDE.md

File metadata and controls

49 lines (33 loc) · 1.58 KB

agent

Minimal AI agent framework in Go. Zero external dependencies. Talks to an OpenAI-compatible API at http://workstation:8080/v1/chat/completions.

Build & Run

go build -o agent .
./agent

Architecture

The agent runs a read-eval-loop: read user input from stdin, send conversation to LLM, execute any tool calls, feed results back, repeat until the model returns a plain text reply.

main.go → stdin scanner + wiring
agent.go → Agent struct: Run() drives the REPL, loop() drives the tool-call cycle, callLLM() handles HTTP
tools/   → Tool interface + implementations

Agent loop (agent.go:loop)

  1. Send conversation to LLM via callLLM
  2. If response contains tool_calls → execute each via executeTool, append results, goto 1
  3. Otherwise return the text reply

Tool system (tools/tool.go)

Tools implement a two-method interface:

  • Definition() Definition — returns name, description, and JSON Schema parameters (OpenAI function-calling format)
  • Execute(params json.RawMessage) (string, error) — runs the tool, returns a result string

Register tools in main.go via agent.Register(...).

Files

File Purpose
main.go Entry point: stdin reader, tool registration, agent.Run()
agent.go Agent struct, LLM communication, agentic tool-call loop
tools/tool.go Tool interface and Definition struct
tools/create_file.go create_file tool: writes a file to disk

Adding a tool

  1. Create tools/my_tool.go implementing tools.Tool
  2. Register in main.go: agent.Register(tools.MyTool{})