agent_kit

Version, currently main branch1 version
  • main branchlatestMay 12, 2026

github.com/alexkutsan/AgentKit

AgentKit - Crystal library for building AI agents with MCP (Model Context Protocol) support. Event-based API for integrating LLM agents into your applications.

0 stars
0 dependents
License: MIT

Installation

# Add this to your shard.yml
dependencies:
  agent_kit:
    github: alexkutsan/AgentKit
    branch: main

main is a branch, not a release, so this tracks it rather than pinning a version.

Then run:

shards install

shard.yml

Crystal
>= 1.19.0
License
MIT
Author
Alexander Kutsan

Dependencies

Runtime Dependencies

Development Dependencies

  • ameba*github: crystal-ameba/amebadev
  • webmock*github: manastech/webmock.crdev

README

AgentKit

Crystal library for building AI agents with MCP (Model Context Protocol) support.

Installation

Add to your shard.yml:

dependencies:
  agent_kit:
    github: alexkutsan/AgentKit
    version: ~> 0.1.0

Then run:

shards install

Requirements

  • Crystal >= 1.19.0
  • OpenAI API key (or compatible provider)

Quick Start

require "agent_kit"

# Create configuration
config = AgentKit::Config.new(
  openai_api_key: ENV["OPENAI_API_KEY"],
  openai_model: "gpt-4o"
)

# Create and run agent
agent = AgentKit::Agent.new(config)

begin
  agent.setup
  result = agent.run("Hello! How are you?")
  puts result
ensure
  agent.cleanup
end

With MCP Server

require "agent_kit"

config = AgentKit::Config.new(
  openai_api_key: ENV["OPENAI_API_KEY"],
  mcp_servers: {
    "tools" => AgentKit::MCPServerConfig.new(
      type: "http",
      url: "http://localhost:8000/mcp"
    )
  }
)

agent = AgentKit::Agent.new(config)

begin
  agent.setup
  result = agent.run("Use the add_numbers tool to add 15 and 27")
  puts result
ensure
  agent.cleanup
end

With Event Handling

require "agent_kit"

config = AgentKit::Config.new(openai_api_key: ENV["OPENAI_API_KEY"])
agent = AgentKit::Agent.new(config)

begin
  agent.setup
  
  result = agent.run("Your prompt here") do |event|
    case event
    when AgentKit::BeforeMCPCallEvent
      puts "Calling tool: #{event.tool_name}"
    when AgentKit::AfterMCPCallEvent
      puts "Tool result: #{event.result}"
    when AgentKit::AgentErrorEvent
      puts "Error: #{event.message}"
    end
  end
  
  puts result
ensure
  agent.cleanup
end

Configuration

config = AgentKit::Config.new(
  openai_api_key: "sk-...",           # Required
  openai_api_host: "https://api.openai.com",  # Default
  openai_model: "gpt-4o",             # Default
  max_iterations: 10,                 # Default
  timeout_seconds: 120,               # Default
  mcp_servers: {} of String => AgentKit::MCPServerConfig
)

config.validate!  # Raises ConfigError if invalid
ParameterDescriptionDefault
openai_api_keyAPI key (required)
openai_api_hostAPI URLhttps://api.openai.com
openai_modelModelgpt-4o
max_iterationsMax agent iterations10
timeout_secondsRequest timeout (sec)120
mcp_serversMCP servers{}

MCP Servers

HTTP Transport

config = AgentKit::Config.new(
  openai_api_key: "sk-...",
  mcp_servers: {
    "filesystem" => AgentKit::MCPServerConfig.new(
      type: "http",
      url: "http://localhost:8000/mcp"
    ),
    "database" => AgentKit::MCPServerConfig.new(
      type: "http",
      url: "http://localhost:8001/mcp",
      headers: {"Authorization" => "Bearer token"}
    )
  }
)

Stdio Transport (local process)

config = AgentKit::Config.new(
  openai_api_key: "sk-...",
  mcp_servers: {
    "local-tools" => AgentKit::MCPServerConfig.new(
      command: "python3",
      args: ["-u", "/path/to/mcp_server.py"],
      env: {"TOKEN" => "secret"}
    )
  }
)

Events

EventDescriptionFields
BeforeMCPCallEventBefore MCP tool calltool_name, arguments
AfterMCPCallEventAfter MCP tool calltool_name, result, error?
BeforeLLMCallEventBefore LLM requestmessages, tools
AfterLLMCallEventAfter LLM responseresponse, final?
AgentCompletedEventAgent finishedresult
AgentErrorEventError occurrederror, message

Events auto-continue by default. Call event.stop! to halt the agent.


Provider Compatibility

Compatible with any OpenAI-compatible API:

Provideropenai_api_host
OpenAIhttps://api.openai.com
Azure OpenAIhttps://{resource}.openai.azure.com
Ollamahttp://localhost:11434
OpenRouterhttps://openrouter.ai/api
Together AIhttps://api.together.xyz

Documentation


License

MIT