soka 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +46 -0
- data/CLAUDE.md +19 -4
- data/README.md +28 -22
- data/examples/1_basic.rb +0 -2
- data/examples/2_event_handling.rb +0 -1
- data/examples/3_memory.rb +0 -2
- data/lib/soka/agent.rb +3 -3
- data/lib/soka/agent_tool.rb +10 -16
- data/lib/soka/agents/dsl_methods.rb +1 -7
- data/lib/soka/agents/hook_manager.rb +4 -6
- data/lib/soka/configuration.rb +2 -3
- data/lib/soka/engines/concerns/response_parser.rb +9 -21
- data/lib/soka/engines/concerns/response_processor.rb +12 -1
- data/lib/soka/engines/prompts/base.rb +103 -0
- data/lib/soka/engines/prompts/format_helpers.rb +43 -0
- data/lib/soka/engines/prompts/instructions.rb +86 -0
- data/lib/soka/engines/prompts/workflow_rules.rb +98 -0
- data/lib/soka/engines/prompts.rb +13 -0
- data/lib/soka/engines/react.rb +6 -7
- data/lib/soka/engines/reasoning_context.rb +0 -12
- data/lib/soka/llm.rb +4 -4
- data/lib/soka/llms/anthropic.rb +17 -21
- data/lib/soka/llms/base.rb +1 -2
- data/lib/soka/llms/gemini.rb +2 -3
- data/lib/soka/llms/openai.rb +42 -36
- data/lib/soka/result.rb +1 -8
- data/lib/soka/version.rb +1 -1
- data/lib/soka.rb +1 -0
- metadata +26 -5
- data/lib/soka/engines/concerns/prompt_template.rb +0 -121
@@ -1,121 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Soka
|
4
|
-
module Engines
|
5
|
-
module Concerns
|
6
|
-
# Module for handling prompt templates in ReAct engine
|
7
|
-
module PromptTemplate
|
8
|
-
private
|
9
|
-
|
10
|
-
def system_prompt
|
11
|
-
# Use custom instructions if provided, otherwise use default ReAct prompt
|
12
|
-
if custom_instructions
|
13
|
-
combine_with_react_format(custom_instructions)
|
14
|
-
else
|
15
|
-
default_react_prompt
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def default_react_prompt
|
20
|
-
tools_description = format_tools_description(tools)
|
21
|
-
|
22
|
-
<<~PROMPT
|
23
|
-
You are an AI assistant that uses the ReAct (Reasoning and Acting) framework to solve problems step by step.
|
24
|
-
|
25
|
-
You have access to the following tools:
|
26
|
-
#{tools_description}
|
27
|
-
|
28
|
-
#{format_instructions}
|
29
|
-
PROMPT
|
30
|
-
end
|
31
|
-
|
32
|
-
def combine_with_react_format(instructions)
|
33
|
-
tools_description = format_tools_description(tools)
|
34
|
-
|
35
|
-
<<~PROMPT
|
36
|
-
#{instructions}
|
37
|
-
|
38
|
-
You have access to the following tools:
|
39
|
-
#{tools_description}
|
40
|
-
|
41
|
-
#{format_instructions}
|
42
|
-
PROMPT
|
43
|
-
end
|
44
|
-
|
45
|
-
def format_instructions
|
46
|
-
thinking_instruction = build_thinking_instruction(think_in)
|
47
|
-
|
48
|
-
<<~INSTRUCTIONS
|
49
|
-
You must follow this exact format for each step:
|
50
|
-
|
51
|
-
#{thinking_instruction}
|
52
|
-
|
53
|
-
<Thought>Your reasoning about what to do next</Thought>
|
54
|
-
<Action>
|
55
|
-
Tool: tool_name
|
56
|
-
Parameters: {"param1": "value1", "param2": "value2"}
|
57
|
-
</Action>
|
58
|
-
|
59
|
-
#{action_format_rules}
|
60
|
-
INSTRUCTIONS
|
61
|
-
end
|
62
|
-
|
63
|
-
# Build thinking instruction based on language
|
64
|
-
# @param language [String, nil] The language to use for thinking
|
65
|
-
# @return [String] The thinking instruction
|
66
|
-
def build_thinking_instruction(language)
|
67
|
-
return '' unless language
|
68
|
-
|
69
|
-
"Use #{language} for your reasoning in <Thought> tags."
|
70
|
-
end
|
71
|
-
|
72
|
-
# Action format rules
|
73
|
-
# @return [String] The action format rules
|
74
|
-
def action_format_rules
|
75
|
-
<<~RULES
|
76
|
-
STOP HERE after each Action. Do NOT include <Observation> in your response.
|
77
|
-
The system will execute the tool and provide the observation.
|
78
|
-
|
79
|
-
After receiving the observation, you can continue with more Thought/Action cycles or provide a final answer:
|
80
|
-
|
81
|
-
<Final_Answer>Your complete answer to the user's question</Final_Answer>
|
82
|
-
|
83
|
-
Important rules:
|
84
|
-
1. Always start with a <Thought> to analyze the problem
|
85
|
-
2. Use tools when you need information or to perform actions
|
86
|
-
3. Parameters MUST be valid JSON format (e.g., {"query": "weather"} not {query: "weather"})
|
87
|
-
4. For tools without parameters, use empty JSON object: {}
|
88
|
-
5. NEVER include <Observation> tags - wait for the system to provide them
|
89
|
-
6. Provide a clear and complete <Final_Answer> when done
|
90
|
-
7. If you cannot complete the task, explain why in the <Final_Answer>
|
91
|
-
RULES
|
92
|
-
end
|
93
|
-
|
94
|
-
def format_tools_description(tools)
|
95
|
-
return 'No tools available.' if tools.empty?
|
96
|
-
|
97
|
-
tools.map do |tool|
|
98
|
-
schema = tool.class.to_h
|
99
|
-
params_desc = format_parameters(schema[:parameters])
|
100
|
-
|
101
|
-
"- #{schema[:name]}: #{schema[:description]}\n Parameters: #{params_desc}"
|
102
|
-
end.join("\n")
|
103
|
-
end
|
104
|
-
|
105
|
-
def format_parameters(params_schema)
|
106
|
-
return 'none' if params_schema[:properties].empty?
|
107
|
-
|
108
|
-
properties = params_schema[:properties].map do |name, config|
|
109
|
-
required = params_schema[:required].include?(name.to_s) ? '(required)' : '(optional)'
|
110
|
-
type = config[:type]
|
111
|
-
desc = config[:description]
|
112
|
-
|
113
|
-
"#{name} #{required} [#{type}] - #{desc}"
|
114
|
-
end
|
115
|
-
|
116
|
-
properties.join(', ')
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
end
|