regent 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5ca2748be57e491dbf33208cfaf09a8009716daf365845dac771c083c5de6d4
4
- data.tar.gz: 9bcb3ca59f00555aeffdfe27f53cf10bbfb32e0789e00eedd07cc1e6db0d7f0c
3
+ metadata.gz: 9a728784fd3d7720bb7fd96bf2cd22a8d53e59eaed01c9b4240a2cb09023e261
4
+ data.tar.gz: 78ddbe87cf964ca94039f560ddfcb743a14757e551af0847363b0fa82228e4a7
5
5
  SHA512:
6
- metadata.gz: 3f9505c05aea8978afb583224616b4cc1851abad8e484d764be40833269adc4f57eab5d1437f4dfd3b47282a449a288048dcf21121a5d6d1b1361a918c6173d5
7
- data.tar.gz: aaa3d15807126bb4cf4a4d7e27f8b52ab550b5851157c6a5a988fbbe522505a63ee4ce3f7b35487b8826bc52a431d34ba55818e5d167bc454f8f1f1fffeb5aef
6
+ metadata.gz: c0306c99637469cff9e51a9b1b50424e646f38dd601dcb5b36d8eee417e2f280488b3e6c78747c242d78d8213fd6a9e004d3cd7065b692d7dc63a5900bf20e16
7
+ data.tar.gz: 68302a81b5062f54415a89e49513e2186afd0fb6d129dfa1111b33565ade932cbae9e657218d66b37cf2fd58b78103456da0dcc7c52c26948016134117cc4e42
data/README.md CHANGED
@@ -1,19 +1,37 @@
1
1
  ![regent_light](https://github.com/user-attachments/assets/62564dac-b8d7-4dc0-9b63-64c6841b5872)
2
2
 
3
+ <div align="center">
4
+
3
5
  # Regent
6
+ [![Gem Version](https://badge.fury.io/rb/regent.svg)](https://badge.fury.io/rb/regent)
7
+ [![Build](https://github.com/alchaplinsky/regent/actions/workflows/main.yml/badge.svg)](https://github.com/alchaplinsky/regent/actions/workflows/main.yml)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+
10
+ </div>
4
11
 
5
- **Regent** is library for building AI agents with Ruby.
12
+ **Regent** is a small and elegant Ruby framework for building AI agents that can think, reason, and take actions through tools. It provides a clean, intuitive interface for creating agents that can solve complex problems by breaking them down into logical steps.
6
13
 
7
14
  > [!WARNING]
8
15
  > Regent is currently an experiment intended to explore patterns for building easily traceable and debuggable AI agents of different architectures. It is not yet intended to be used in production and is currently in development.
9
16
 
17
+ ## Key Features
18
+
19
+ - **ReAct Pattern Implementation**: Agents follow the Reasoning-Action pattern, making decisions through a clear thought process before taking actions
20
+ - **Multi-LLM Support**: Seamlessly works with:
21
+ - OpenAI (GPT models)
22
+ - Anthropic (Claude models)
23
+ - Google (Gemini models)
24
+ - **Extensible Tool System**: Create custom tools that agents can use to interact with external services, APIs, or perform specific tasks
25
+ - **Built-in Tracing**: Every agent interaction is traced and can be replayed, making debugging and monitoring straightforward
26
+ - **Clean Ruby Interface**: Designed to feel natural to Ruby developers while maintaining powerful capabilities
27
+
10
28
  ## Showcase
11
29
 
12
30
  A basic Regnt Agent extended with a `price_tool` that allows for retrieving cryptocurrency prices from coingecko.com.
13
31
 
14
32
  ![screencast 2024-12-25 21-53-47](https://github.com/user-attachments/assets/4e65b731-bbd7-4732-b157-b705d35a7824)
15
33
 
16
- ## Install
34
+ ## Quick Start
17
35
 
18
36
  ```bash
19
37
  gem install regent
@@ -31,47 +49,41 @@ and run
31
49
  bundle install
32
50
  ```
33
51
 
34
- ## Available LLMs
35
-
36
- Regent currently supports LLMs from the following providers:
37
-
38
- | Provider | Models | Supported |
39
- | ------------- | :--------------------: | :-------: |
40
- | OpenAI | `gpt-` based models | ✅ |
41
- | Anthropic | `claude-` based models | ✅ |
42
- | Google Gemini | `gemini-` based models | ✅ |
43
-
44
52
  ## Usage
45
53
 
46
- In order to operate an agent needs access to LLM (large language model). Regent provides a simple interface for interacting with LLMs. You can create an instance of any LLM provider by passing the model name to the `Regent::LLM.new` method:
54
+ Create your first agent:
47
55
 
48
56
  ```ruby
49
- llm = Regent::LLM.new("gpt-4o-mini")
50
- ```
51
-
52
- Agents are effective when they have tools that enable them to get new information:
57
+ # Initialize the LLM
58
+ llm = Regent::LLM.new("gpt-4o")
53
59
 
54
- ```ruby
60
+ # Create a custom tool
55
61
  class WeatherTool < Regent::Tool
56
62
  def call(location)
57
- # implementation of a call to weather API
63
+ # Implement weather lookup logic
64
+ "Currently 72°F and sunny in #{location}"
58
65
  end
59
66
  end
60
67
 
61
- weather_tool = WeatherTool.new(name: "weather_tool", description: "Get the weather in a given location")
62
- ```
63
-
64
- Next, let's instantiate an agent passing agent's statement, LLM and a set of tools:
65
-
66
- ```ruby
67
- agent = Regent::Agent.new("You are a weather AI agent", llm: llm, tools: [weather_tool])
68
+ # Create and configure the agent
69
+ agent = Regent::Agent.new(
70
+ "You are a helpful weather assistant",
71
+ llm: llm,
72
+ tools: [WeatherTool.new(
73
+ name: "weather_tool",
74
+ description: "Get current weather for a location"
75
+ )]
76
+ )
77
+
78
+ # Execute a query
79
+ result = agent.execute("What's the weather like in Tokyo?") # => "It is currently 72°F and sunny in Tokyo."
68
80
  ```
69
81
 
70
- Simply run an execute function, passing your query as an argument
71
-
72
- ```ruby
73
- agent.execute("What is the weather in London today?")
74
- ```
82
+ ## Why Regent?
83
+ - **Transparent Decision Making**: Watch your agent's thought process as it reasons through problems
84
+ - **Flexible Architecture**: Easy to extend with custom tools and adapt to different use cases
85
+ - **Production Ready**: Built with tracing, error handling, and clean abstractions
86
+ - **Ruby-First Design**: Takes advantage of Ruby's elegant syntax and conventions
75
87
 
76
88
  ## Development
77
89
 
@@ -11,7 +11,7 @@ module Regent
11
11
  You are an AI agent reasoning step-by-step to solve complex problems.
12
12
  Your reasoning process happens in a loop of Thought, Action, Observation.
13
13
  Thought - a description of your thoughts about the question.
14
- Action - pick a an action from available tools. If there are no tools that can help return an Answer saying you are not able to help.
14
+ Action - pick a an action from available tools if required. If there are no tools that can help return an Answer saying you are not able to help.
15
15
  Observation - is the result of running a tool.
16
16
  PAUSE - is always present after an Action.
17
17
 
@@ -44,7 +44,7 @@ module Regent
44
44
  def initialize_session(task)
45
45
  session.add_message({role: :system, content: Regent::Engine::React::PromptTemplate.system_prompt(context, toolchain.to_s)})
46
46
  session.add_message({role: :user, content: task})
47
- session.exec(Span::Type::INPUT, message: task) { task }
47
+ session.exec(Span::Type::INPUT, top_level: true, message: task) { task }
48
48
  end
49
49
 
50
50
  def get_llm_response
@@ -83,11 +83,11 @@ module Regent
83
83
  end
84
84
 
85
85
  def success_answer(content)
86
- session.exec(Span::Type::ANSWER, type: :success, message: content, duration: session.duration.round(2)) { content }
86
+ session.exec(Span::Type::ANSWER, top_level: true,type: :success, message: content, duration: session.duration.round(2)) { content }
87
87
  end
88
88
 
89
89
  def error_answer(content)
90
- session.exec(Span::Type::ANSWER, type: :failure, message: content, duration: session.duration.round(2)) { content }
90
+ session.exec(Span::Type::ANSWER, top_level: true, type: :failure, message: content, duration: session.duration.round(2)) { content }
91
91
  end
92
92
 
93
93
  def lookup_tool(content)
data/lib/regent/llm.rb CHANGED
@@ -20,7 +20,7 @@ module Regent
20
20
  attr_reader :model, :options
21
21
 
22
22
  def invoke(messages, **args)
23
- response = provider.invoke(messages, **args)
23
+ provider.invoke(messages, **args)
24
24
  end
25
25
 
26
26
  private
data/lib/regent/logger.rb CHANGED
@@ -4,10 +4,10 @@ module Regent
4
4
  class Logger
5
5
  COLORS = %i[dim green yellow red blue cyan clear].freeze
6
6
 
7
- def initialize
7
+ def initialize(output: $stdout)
8
8
  @pastel = Pastel.new
9
- @spinner = build_spinner(spinner_symbol)
10
- @nested_spinner = build_spinner("#{dim(" ├──")}#{spinner_symbol}")
9
+ @spinner = build_spinner(spinner_symbol, output)
10
+ @nested_spinner = build_spinner("#{dim(" ├──")}#{spinner_symbol}", output)
11
11
  end
12
12
 
13
13
  attr_reader :spinner, :nested_spinner
@@ -50,8 +50,8 @@ module Regent
50
50
  "#{dim("[")}#{green(":spinner")}#{dim("]")}"
51
51
  end
52
52
 
53
- def build_spinner(spinner_format)
54
- TTY::Spinner.new("#{spinner_format} :title", format: :dots)
53
+ def build_spinner(spinner_format, output)
54
+ TTY::Spinner.new("#{spinner_format} :title", format: :dots, output: output)
55
55
  end
56
56
 
57
57
  COLORS.each do |color|
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Regent
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Chaplinsky
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-28 00:00:00.000000000 Z
11
+ date: 2024-12-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk