Minimal AI agent framework in Go. Zero external dependencies. Talks to an OpenAI-compatible API at http://workstation:8080/v1/chat/completions.
go build -o agent .
./agentThe 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
- Send conversation to LLM via
callLLM - If response contains
tool_calls→ execute each viaexecuteTool, append results, goto 1 - Otherwise return the text reply
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(...).
| 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 |
- Create
tools/my_tool.goimplementingtools.Tool - Register in
main.go:agent.Register(tools.MyTool{})