{"id":24333622,"url":"https://github.com/graysonchen/ruby-openai-swarm","last_synced_at":"2025-10-25T05:12:21.031Z","repository":{"id":259699258,"uuid":"878005021","full_name":"graysonchen/ruby-openai-swarm","owner":"graysonchen","description":"A Ruby-based educational framework adapted from OpenAI’s Swarm, exploring ergonomic, lightweight multi-agent orchestration.","archived":false,"fork":false,"pushed_at":"2025-01-17T10:14:32.000Z","size":332,"stargazers_count":7,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-17T11:24:40.305Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/graysonchen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-24T15:56:57.000Z","updated_at":"2025-01-17T10:14:33.000Z","dependencies_parsed_at":"2024-10-27T12:59:50.475Z","dependency_job_id":"dec549b0-6370-48ad-a5ba-d7df9d52f0dd","html_url":"https://github.com/graysonchen/ruby-openai-swarm","commit_stats":null,"previous_names":["graysonchen/ruby-openai-swarm"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graysonchen%2Fruby-openai-swarm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graysonchen%2Fruby-openai-swarm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graysonchen%2Fruby-openai-swarm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/graysonchen%2Fruby-openai-swarm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/graysonchen","download_url":"https://codeload.github.com/graysonchen/ruby-openai-swarm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234456018,"owners_count":18835674,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-18T03:18:05.472Z","updated_at":"2025-09-27T20:31:25.123Z","avatar_url":"https://github.com/graysonchen.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"![Swarm Logo](assets/logo-swarm.png)\n\n# Ruby OpenAI Swarm\n\n[![Gem Version](https://img.shields.io/gem/v/ruby-openai-swarm.svg)](https://rubygems.org/gems/ruby-openai-swarm)\n[![rspec](https://github.com/graysonchen/ruby-openai-swarm/actions/workflows/rspec.yml/badge.svg)](https://github.com/graysonchen/ruby-openai-swarm/actions)\n\nA Ruby-based educational framework adapted from OpenAI’s [Swarm](https://github.com/openai/swarm), exploring ergonomic, lightweight multi-agent orchestration.\n\n\u003e The primary goal of Swarm is to showcase the handoff \u0026 routines patterns explored in the [Orchestrating Agents: Handoffs \u0026 Routines](https://cookbook.openai.com/examples/orchestrating_agents) cookbook. It is not meant as a standalone library, and is primarily for educational purposes.\n\n## Contents\n- [Ruby OpenAI Swarm](#ruby-openai-swarm)\n- [Table of Contents](#table-of-contents)\n  - [Installation](#installation)\n    - [Bundler](#bundler)\n    - [Gem install](#gem-install)\n    - [Logger](#logger)\n  - [Quick start](#quick-start)\n  - [Documentation](#documentation)\n\n## quick show\nhttps://github.com/user-attachments/assets/ed84ef83-5ccb-4223-abb8-933d0ec66468\n\n\n## Installation\n\n### Bundler\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"ruby-openai-swarm\"\n```\n\nAnd then execute:\n\n```bash\n$ bundle install\n```\n\n### Gem install\n\nOr install with:\n\n```bash\n$ gem install ruby-openai-swarm\n```\n\nand require with:\n\n```ruby\nrequire \"ruby-openai-swarm\"\n```\n\n## Usage\n\n### With Config\n\nFor a more robust setup, you can configure the gem with your API keys, for example in an `openai.rb` initializer file. Never hardcode secrets into your codebase - instead use something like [dotenv](https://github.com/motdotla/dotenv) to pass the keys safely into your environments.\n\n```ruby\nOpenAI.configure do |config|\n  config.access_token = ENV['OPENAI_ACCESS_TOKEN']\nend\n```\n\nOR\n\n```ruby\n# https://openrouter.ai\nOpenAI.configure do |config|\n  config.access_token = ENV['OPEN_ROUTER_ACCESS_TOKEN']\n  config.uri_base = \"https://openrouter.ai/api/v1\"\nend\n```\n\nmore see: https://github.com/alexrudall/ruby-openai/tree/main?tab=readme-ov-file#ollama\n\nThen you can create a client like this:\n\n```ruby\nclient = OpenAISwarm.new\n\ndef spanish_agent\n  OpenAISwarm::Agent.new(\n    name: \"Spanish Agent\",\n    instructions: \"You only speak Spanish.\",\n    model: ENV['SWARM_AGENT_DEFAULT_MODEL']\n  )\nend\n\ntransfer_to_spanish_agent = OpenAISwarm::FunctionDescriptor.new(\n  target_method: :spanish_agent,\n  description: 'Transfer spanish speaking users immediately.'\n)\n\nenglish_agent = OpenAISwarm::Agent.new(\n  name: \"English Agent\",\n  instructions: \"You only speak English.\",\n  model: ENV['SWARM_AGENT_DEFAULT_MODEL'],\n  functions: [transfer_to_spanish_agent]\n)\n\nmessages = [{\"role\": \"user\", \"content\": \"Hola. ¿Como estás?\"}]\nresponse = client.run(agent: english_agent, messages: messages, debug: true)\n\npp response.messages.last\n```\n\n```ruby\n{\"role\"=\u003e\"assistant\",\n \"content\"=\u003e\"¡Hola! Estoy bien, gracias. ¿Y tú?\",\n \"refusal\"=\u003enil,\n :sender=\u003e\"Spanish Agent\"}\n```\n\n### Logger\n\n```\nOpenAISwarm.configure do |config|\n  # config.logger = Logger.new(STDOUT)\n  # config.logger = Rails.logger\n  config.log_file = Rails.root.join('log', 'openai_swarm.log')\n  # config.logger = Logger.new(Rails.root.join('log', 'openai_swarm.log'))\n  # config.logger = Rails.configuration.lograge.logger\nend\n```\n\n## Quick Start\n\n### Choose the default model name\n\n`export SWARM_AGENT_DEFAULT_MODEL=gpt-4o-mini`\n\nor\n\n`export SWARM_AGENT_DEFAULT_MODEL=deepseek-chat`\n\nDeepSeek V3 is 1/10 price of gpt-4o-mini, so try it!\n\n\n### Setting ACCESS_TOKEN for AI Providers in examples\n\n- For OpenRouter:\n\n  `OPEN_ROUTER_ACCESS_TOKEN=cxxxxx` or `export OPEN_ROUTER_ACCESS_TOKEN=cxxxxx`\n\n- For OpenAI:\n\n  `OPENAI_ACCESS_TOKEN=cxxxxx` or `export OPENAI_ACCESS_TOKEN=cxxxxx`\n\n- For DeepSeek:\n\n  `DEEPSEEK_ACCESS_TOKEN=cxxxxx` or `export DEEPSEEK_ACCESS_TOKEN=cxxxxx`\n\n### Check out `/examples` for inspiration! Learn more about each one in its README.\n\n- [X] [`basic`](examples/basic): Simple examples of fundamentals like setup, function calling, handoffs, and context variables\n  - running: `ruby examples/basic/agent_handoff.rb`\n  - running: `ruby examples/basic/bare_minimum.rb`\n  - running: `ruby examples/basic/context_variables.rb`\n  - running: `ruby examples/basic/function_calling.rb`\n  - running: `ruby examples/basic/simple_loop_no_helpers.rb`\n- [X] [`triage_agent`](examples/triage_agent): Simple example of setting up a basic triage step to hand off to the right agent\n  - running: `ruby examples/triage_agent/main.rb`\n- [X] [`weather_agent`](examples/weather_agent): Simple example of function calling\n  - running: `ruby examples/weather_agent/run.rb`\n- [X] [`airline`](examples/airline): A multi-agent setup for handling different customer service requests in an airline context.\n  - running: `DEBUG=1 ruby examples/airline/main.rb`\n- [ ] [`support_bot`](examples/support_bot): A customer service bot which includes a user interface agent and a help center agent with several tools\n- [ ] [`personal_shopper`](examples/personal_shopper): A personal shopping agent that can help with making sales and refunding orders\n\nlink: https://github.com/openai/swarm/tree/main?tab=readme-ov-file#examples\n\n## Documentation\n![Swarm Diagram](https://raw.githubusercontent.com/openai/swarm/refs/heads/main/assets/swarm_diagram.png)\n\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/graysonchen/ruby-openai-swarm. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/graysonchen/ruby-openai-swarm/blob/main/CODE_OF_CONDUCT.md).\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraysonchen%2Fruby-openai-swarm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgraysonchen%2Fruby-openai-swarm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgraysonchen%2Fruby-openai-swarm/lists"}