language-operator 0.1.70 โ†’ 0.1.71

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d6a8a654ac7b3fea9f1d176029ba86153b44cc746dacb8173054c6c2e0740def
4
- data.tar.gz: d67180ae9aa7e99ad55b0764936028348039359367320a7e76afad95d5cd84a6
3
+ metadata.gz: 11da2ddaf7396a49d94451edc45cd07a05b8ac2d9239b587f46cf7b5a938714f
4
+ data.tar.gz: 998d0061d7a4a7fee8a61de4b034766bceb4421363cf177b4e6e38ada37c04b0
5
5
  SHA512:
6
- metadata.gz: 7244d148d067fb2733a23c193c499bb13bc336891cdd5fbbb932cc1ecf40111cf2bfb8f3e25ac9cd290b655915a3e2ab5e3c88bfb133063ba47991835d7e485e
7
- data.tar.gz: d11fa46700dd377f76804c3808848b4ee321982db18c25611834b660c60babbffb80fbcfe26abc8e32d21e01b26776fdb97f699b7e769d6a7a2337fadea591ba
6
+ metadata.gz: 44f424c8f7ff4a5d147f86027a7e68e4bfacbda5ed3a0747793c35e5967d58e339b001dc421eb3826c6d1cd359343fc74ea9de96cc0e1d5eeefd45d101ca3d1e
7
+ data.tar.gz: b74bcaf2d2762cccb6c282041b3cd40d6c1ffd6635dfc1920855f68ffbf9bbe8c46e5e8bb052e77d4807d0ba2c28eaf92b516649be4891cd64ca1a04ceaf476f
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- language-operator (0.1.70)
4
+ language-operator (0.1.71)
5
5
  faraday (~> 2.0)
6
6
  json-schema (~> 5.0)
7
7
  k8s-ruby (~> 0.17)
@@ -2,7 +2,7 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'language-operator', '~> 0.1.66'
5
+ gem 'language-operator', '~> 0.1.70'
6
6
 
7
7
  # Agent-specific dependencies for autonomous execution
8
8
  gem 'concurrent-ruby', '~> 1.3'
@@ -0,0 +1,346 @@
1
+ # Persona-Driven System Prompts
2
+
3
+ Language Operator v0.1.71+ introduces **persona-driven system prompts** that transform agents from generic chatbots into context-aware entities with deep understanding of their identity, role, environment, and operational state.
4
+
5
+ ## Overview
6
+
7
+ Traditional AI agents respond with generic outputs lacking awareness of their purpose or context. With persona-driven prompts, agents become intelligent entities that:
8
+
9
+ - **Know their identity**: Name, role, and specific purpose
10
+ - **Understand their environment**: Cluster, namespace, operational mode
11
+ - **Track operational state**: Uptime, status, capabilities, tools available
12
+ - **Provide contextual responses**: References to their actual function and situation
13
+
14
+ ## Quick Example
15
+
16
+ **Before (Generic Response):**
17
+ ```
18
+ User: "hello"
19
+ Agent: "Hello! How can I assist you today?"
20
+ ```
21
+
22
+ **After (Identity-Aware Response):**
23
+ ```
24
+ User: "hello"
25
+ Agent: "Hello! I'm say-something, running in the code-games cluster.
26
+ I've been active for 3 hours now, helping log interesting messages
27
+ and interactions. How can I assist you today?"
28
+ ```
29
+
30
+ ## Configuration
31
+
32
+ ### Basic Usage
33
+
34
+ Enable identity awareness in your chat endpoint:
35
+
36
+ ```ruby
37
+ agent "support-bot" do
38
+ description "Customer support assistant"
39
+ mode :reactive
40
+
41
+ as_chat_endpoint do
42
+ system_prompt "You are a helpful customer support assistant"
43
+
44
+ # Enable persona-driven prompts
45
+ identity_awareness do
46
+ enabled true
47
+ prompt_template :standard
48
+ context_injection :standard
49
+ end
50
+ end
51
+ end
52
+ ```
53
+
54
+ ### Template Levels
55
+
56
+ Choose how much context to inject into system prompts:
57
+
58
+ #### `:minimal` - Basic Identity Only
59
+ ```ruby
60
+ identity_awareness do
61
+ enabled true
62
+ prompt_template :minimal
63
+ end
64
+ ```
65
+
66
+ **Generated prompt includes:**
67
+ - Agent name and cluster location
68
+ - Basic operational status
69
+
70
+ #### `:standard` - Balanced Context (Default)
71
+ ```ruby
72
+ identity_awareness do
73
+ enabled true
74
+ prompt_template :standard # Default
75
+ end
76
+ ```
77
+
78
+ **Generated prompt includes:**
79
+ - Agent identity (name, role, mode)
80
+ - Basic operational context (uptime, cluster, status)
81
+ - Behavioral guidelines
82
+
83
+ #### `:detailed` - Full Context with Capabilities
84
+ ```ruby
85
+ identity_awareness do
86
+ enabled true
87
+ prompt_template :detailed
88
+ end
89
+ ```
90
+
91
+ **Generated prompt includes:**
92
+ - Complete identity and operational context
93
+ - Available tools and capabilities
94
+ - Workspace status and environment details
95
+ - Detailed behavioral guidelines
96
+
97
+ #### `:comprehensive` - Maximum Context
98
+ ```ruby
99
+ identity_awareness do
100
+ enabled true
101
+ prompt_template :comprehensive
102
+ end
103
+ ```
104
+
105
+ **Generated prompt includes:**
106
+ - All available metadata
107
+ - Environment specifications
108
+ - Complete capability listing
109
+ - Full behavioral framework
110
+
111
+ ### Context Injection Levels
112
+
113
+ Control how much operational context appears in ongoing conversations:
114
+
115
+ ```ruby
116
+ identity_awareness do
117
+ enabled true
118
+ context_injection :standard # Options: :none, :minimal, :standard, :detailed
119
+ end
120
+ ```
121
+
122
+ - **`:none`** - No conversation context injection
123
+ - **`:minimal`** - Basic status only
124
+ - **`:standard`** - Agent name, mode, uptime, status
125
+ - **`:detailed`** - Full operational metrics
126
+
127
+ ## Implementation Details
128
+
129
+ ### Architecture
130
+
131
+ The persona-driven prompt system consists of:
132
+
133
+ 1. **MetadataCollector** - Gathers agent runtime and configuration data
134
+ 2. **PromptBuilder** - Generates dynamic prompts from templates and metadata
135
+ 3. **ChatEndpointDefinition** - Enhanced with identity awareness configuration
136
+ 4. **WebServer** - Integrates dynamic prompts into conversation handling
137
+
138
+ ### Available Metadata
139
+
140
+ Agents can access the following runtime information:
141
+
142
+ ```ruby
143
+ {
144
+ identity: {
145
+ name: "support-bot",
146
+ description: "Customer support assistant",
147
+ persona: "helpful-assistant",
148
+ mode: "reactive",
149
+ version: "0.1.71"
150
+ },
151
+ runtime: {
152
+ uptime: "3h 45m",
153
+ started_at: "2024-01-15T10:30:00Z",
154
+ workspace_available: true,
155
+ mcp_servers_connected: 2
156
+ },
157
+ environment: {
158
+ cluster: "production",
159
+ namespace: "support",
160
+ kubernetes_enabled: true,
161
+ telemetry_enabled: true
162
+ },
163
+ operational: {
164
+ status: "ready",
165
+ ready: true,
166
+ mode: "reactive"
167
+ },
168
+ capabilities: {
169
+ total_tools: 5,
170
+ tools: [
171
+ { server: "github-tools", tool_count: 3 },
172
+ { server: "slack-tools", tool_count: 2 }
173
+ ],
174
+ llm_provider: "anthropic",
175
+ llm_model: "claude-3-haiku"
176
+ }
177
+ }
178
+ ```
179
+
180
+ ## Migration Guide
181
+
182
+ ### Existing Agents
183
+
184
+ Persona-driven prompts are **backward compatible**. Existing agents continue working without changes.
185
+
186
+ To enable for existing agents:
187
+
188
+ ```ruby
189
+ # Before
190
+ as_chat_endpoint do
191
+ system_prompt "You are a GitHub expert"
192
+ temperature 0.7
193
+ end
194
+
195
+ # After - Add identity awareness
196
+ as_chat_endpoint do
197
+ system_prompt "You are a GitHub expert"
198
+
199
+ identity_awareness do
200
+ enabled true # Enable the feature
201
+ prompt_template :standard
202
+ context_injection :standard
203
+ end
204
+
205
+ temperature 0.7
206
+ end
207
+ ```
208
+
209
+ ### Gradual Adoption
210
+
211
+ 1. **Start with `:minimal`** template to test basic identity awareness
212
+ 2. **Upgrade to `:standard`** for balanced context
213
+ 3. **Use `:detailed`** for rich conversational experiences
214
+ 4. **Apply `:comprehensive`** only when maximum context is needed
215
+
216
+ ### Disabling Features
217
+
218
+ ```ruby
219
+ # Disable completely
220
+ identity_awareness do
221
+ enabled false
222
+ end
223
+
224
+ # Disable conversation context only
225
+ identity_awareness do
226
+ enabled true
227
+ prompt_template :standard
228
+ context_injection :none
229
+ end
230
+ ```
231
+
232
+ ## Best Practices
233
+
234
+ ### Template Selection
235
+
236
+ - **Customer-facing agents**: Use `:standard` or `:detailed`
237
+ - **Internal tools**: Use `:detailed` or `:comprehensive`
238
+ - **Simple utilities**: Use `:minimal`
239
+ - **Legacy compatibility**: Use `enabled false`
240
+
241
+ ### Performance Considerations
242
+
243
+ - Metadata collection is lightweight but cached
244
+ - Higher template levels increase token usage
245
+ - Context injection adds minimal overhead
246
+ - Templates are generated once per conversation
247
+
248
+ ### Security
249
+
250
+ - No sensitive information (secrets, keys) included in prompts
251
+ - Environment details are cluster/namespace level only
252
+ - PII detection prevents accidental exposure
253
+
254
+ ## Examples
255
+
256
+ ### Complete Identity-Aware Agent
257
+
258
+ ```ruby
259
+ LanguageOperator::Dsl.define do
260
+ agent "customer-support" do
261
+ description "24/7 customer support specialist for SaaS platform"
262
+ mode :reactive
263
+
264
+ as_chat_endpoint do
265
+ system_prompt <<~PROMPT
266
+ You are a knowledgeable customer support specialist with expertise in:
267
+ - Account management and billing
268
+ - Product features and troubleshooting
269
+ - Technical documentation and guides
270
+
271
+ Provide helpful, accurate, and empathetic support to customers.
272
+ PROMPT
273
+
274
+ identity_awareness do
275
+ enabled true
276
+ prompt_template :detailed
277
+ context_injection :standard
278
+ end
279
+
280
+ model "customer-support-v1"
281
+ temperature 0.7
282
+ max_tokens 2000
283
+ end
284
+
285
+ constraints do
286
+ requests_per_minute 30
287
+ daily_budget 1000
288
+ end
289
+ end
290
+ end
291
+ ```
292
+
293
+ ### Development vs Production Templates
294
+
295
+ ```ruby
296
+ # Development - comprehensive context for debugging
297
+ identity_awareness do
298
+ enabled true
299
+ prompt_template :comprehensive
300
+ context_injection :detailed
301
+ end
302
+
303
+ # Production - balanced context for performance
304
+ identity_awareness do
305
+ enabled true
306
+ prompt_template :standard
307
+ context_injection :standard
308
+ end
309
+ ```
310
+
311
+ ## Troubleshooting
312
+
313
+ ### Common Issues
314
+
315
+ **Agent still gives generic responses:**
316
+ - Verify `enabled true` in identity_awareness block
317
+ - Check agent has proper name and description
318
+ - Ensure cluster environment variables are set
319
+
320
+ **Prompts too long/expensive:**
321
+ - Reduce template level (`:detailed` โ†’ `:standard` โ†’ `:minimal`)
322
+ - Disable context injection (`:none`)
323
+
324
+ **Missing environment context:**
325
+ - Verify Kubernetes environment variables
326
+ - Check cluster and namespace configuration
327
+ - Ensure agent has proper metadata access
328
+
329
+ ### Debug Information
330
+
331
+ Enable debug logging to see generated prompts:
332
+
333
+ ```bash
334
+ DEBUG=true ruby examples/identity_aware_chat_agent.rb
335
+ ```
336
+
337
+ ## API Reference
338
+
339
+ See the complete API documentation:
340
+ - [`ChatEndpointDefinition`](api/chat-endpoint-definition.md)
341
+ - [`MetadataCollector`](api/metadata-collector.md)
342
+ - [`PromptBuilder`](api/prompt-builder.md)
343
+
344
+ ---
345
+
346
+ **Next Steps:** Try the [identity-aware chat agent example](../examples/identity_aware_chat_agent.rb) to see persona-driven prompts in action.
@@ -0,0 +1,99 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Basic Agent with Default Chat Endpoint
5
+ #
6
+ # This example demonstrates that agents automatically expose chat endpoints
7
+ # without explicitly defining them via as_chat_endpoint.
8
+ #
9
+ # This agent:
10
+ # - Runs autonomous work (logging every 10 seconds)
11
+ # - Automatically exposes chat endpoint at /v1/chat/completions
12
+ # - No explicit as_chat_endpoint block needed!
13
+ #
14
+ # Usage:
15
+ # ruby examples/basic_agent_with_default_chat.rb
16
+ #
17
+ # Test default chat endpoint:
18
+ # curl -X POST http://localhost:8080/v1/chat/completions \
19
+ # -H "Content-Type: application/json" \
20
+ # -d '{
21
+ # "model": "basic-worker",
22
+ # "messages": [
23
+ # {"role": "user", "content": "What are you doing right now?"}
24
+ # ]
25
+ # }'
26
+
27
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
28
+
29
+ require 'language_operator'
30
+
31
+ # Define a basic agent - NO explicit chat endpoint!
32
+ agent "basic-worker" do
33
+ description "Simple worker that performs basic tasks"
34
+ mode :autonomous
35
+
36
+ # Simple main loop - this is the autonomous work
37
+ task :do_work,
38
+ instructions: "Perform some basic work and log progress",
39
+ inputs: {},
40
+ outputs: {
41
+ work_done: 'boolean',
42
+ message: 'string',
43
+ timestamp: 'string'
44
+ }
45
+
46
+ main do |inputs|
47
+ puts "๐Ÿ”จ Performing autonomous work..."
48
+
49
+ # Execute the work task
50
+ work_result = execute_task(:do_work)
51
+
52
+ puts "โœ… Work completed: #{work_result[:message]}"
53
+ puts "๐Ÿ˜ด Sleeping for 10 seconds..."
54
+
55
+ sleep 10
56
+
57
+ work_result
58
+ end
59
+
60
+ # Basic constraints
61
+ constraints do
62
+ max_iterations 999999
63
+ timeout '30s'
64
+ end
65
+ end
66
+
67
+ # Start the agent
68
+ if __FILE__ == $PROGRAM_NAME
69
+ puts "๐Ÿš€ Starting Basic Agent with Default Chat Endpoint"
70
+ puts ""
71
+ puts "This agent demonstrates automatic chat endpoint creation:"
72
+ puts " โœ… Runs autonomous work every 10 seconds"
73
+ puts " โœ… Automatically exposes chat at /v1/chat/completions"
74
+ puts " โœ… No explicit as_chat_endpoint block needed!"
75
+ puts ""
76
+ puts "Agent info:"
77
+ puts " Name: basic-worker"
78
+ puts " Description: Simple worker that performs basic tasks"
79
+ puts " Mode: autonomous"
80
+ puts ""
81
+ puts "Available endpoints (auto-generated):"
82
+ puts " POST /v1/chat/completions - Chat with basic-worker"
83
+ puts " GET /v1/models - Available models"
84
+ puts " GET /health - Health check"
85
+ puts " GET /ready - Readiness check"
86
+ puts ""
87
+ puts "Test command:"
88
+ puts "curl -X POST http://localhost:8080/v1/chat/completions \\"
89
+ puts ' -H "Content-Type: application/json" \\'
90
+ puts ' -d \'{"model": "basic-worker", "messages": [{"role": "user", "content": "What are you doing?"}]}\''
91
+ puts ""
92
+ puts "Expected system prompt (auto-generated):"
93
+ puts '"You are simple worker that performs basic tasks. Provide helpful assistance based on your capabilities."'
94
+ puts ""
95
+ puts "Press Ctrl+C to stop"
96
+ puts "=" * 80
97
+
98
+ LanguageOperator::Agent.run
99
+ end
@@ -26,27 +26,15 @@ require 'language_operator'
26
26
  # Define an agent with chat endpoint capabilities
27
27
  LanguageOperator::Dsl.define do
28
28
  agent "github-expert" do
29
- description "GitHub API and workflow expert"
29
+ description "You are a GitHub expert assistant with deep knowledge of GitHub API, workflows, pull requests, issues, code review, GitHub Actions, CI/CD, and repository management best practices"
30
30
  mode :reactive
31
31
 
32
- # This is the key - expose the agent as an OpenAI-compatible chat endpoint
33
- as_chat_endpoint do
34
- system_prompt <<~PROMPT
35
- You are a GitHub expert assistant with deep knowledge of:
36
- - GitHub API and workflows
37
- - Pull requests, issues, and code review
38
- - GitHub Actions and CI/CD
39
- - Repository management and best practices
40
-
41
- Provide helpful, accurate answers about GitHub topics.
42
- Keep responses concise but informative.
43
- PROMPT
44
-
45
- # Configure the endpoint parameters
46
- model "github-expert-v1" # Model name returned in API responses
47
- temperature 0.7 # Balanced creativity and consistency
48
- max_tokens 2000 # Limit response length
49
- end
32
+ # Chat endpoint is automatic! No configuration needed.
33
+ # Every agent automatically gets:
34
+ # - OpenAI-compatible chat endpoint at /v1/chat/completions
35
+ # - Identity-aware responses with agent context
36
+ # - Operational state awareness (uptime, cluster, etc.)
37
+ # - Professional, contextual conversation style
50
38
 
51
39
  # Optional: Add constraints for safety and cost management
52
40
  constraints do
@@ -0,0 +1,83 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Identity-Aware Chat Agent Example
5
+ #
6
+ # This example demonstrates automatic persona-driven system prompts that provide
7
+ # ALL agents with awareness of their identity, role, environment, and operational context.
8
+ #
9
+ # Key Features (AUTOMATIC):
10
+ # - Agent knows its name, role, and purpose
11
+ # - Operational context (uptime, cluster, status) awareness
12
+ # - Environment information (namespace, tools available)
13
+ # - Professional, contextual conversation style
14
+ #
15
+ # Usage:
16
+ # ruby examples/identity_aware_chat_agent.rb
17
+ #
18
+ # Test with:
19
+ # curl -X POST http://localhost:8080/v1/chat/completions \
20
+ # -H "Content-Type: application/json" \
21
+ # -d '{"model": "say-something-v2", "messages": [{"role": "user", "content": "hello"}]}'
22
+
23
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
24
+
25
+ require 'language_operator'
26
+
27
+ # Define an identity-aware agent
28
+ LanguageOperator::Dsl.define do
29
+ agent "say-something" do
30
+ description "A helpful assistant that specializes in creating engaging, concise messages and interactions. You excel at understanding context and providing meaningful responses that fit the conversation."
31
+ mode :reactive
32
+
33
+ # Identity-aware chat endpoint is automatic!
34
+ # No configuration needed - every agent gets it by default.
35
+
36
+ # Add some constraints for safety
37
+ constraints do
38
+ timeout '30s'
39
+ requests_per_minute 20
40
+ daily_budget 500 # $5/day
41
+ end
42
+ end
43
+ end
44
+
45
+ # Start the agent
46
+ if __FILE__ == $PROGRAM_NAME
47
+ puts "๐Ÿš€ Starting Identity-Aware Say-Something Agent..."
48
+ puts ""
49
+ puts "ALL agents automatically include persona-driven system prompts with:"
50
+ puts " โœ“ Agent identity awareness (name, role, purpose)"
51
+ puts " โœ“ Operational context (uptime, status, environment)"
52
+ puts " โœ“ Dynamic prompt generation based on current state"
53
+ puts " โœ“ Professional, contextual conversation style"
54
+ puts ""
55
+ puts "Server will be available at http://localhost:8080"
56
+ puts ""
57
+ puts "๐Ÿ“ Example conversation:"
58
+ puts " User: 'hello'"
59
+ puts " Agent: 'Hello! I'm say-something, running in the code-games cluster."
60
+ puts " I've been active for 15m now, helping log interesting messages"
61
+ puts " and interactions. How can I assist you today?'"
62
+ puts ""
63
+ puts "๐Ÿ”ง Endpoints:"
64
+ puts " POST /v1/chat/completions - Chat completion (OpenAI-compatible)"
65
+ puts " GET /v1/models - List available models"
66
+ puts " GET /health - Health check"
67
+ puts " GET /ready - Readiness check"
68
+ puts ""
69
+ puts "๐Ÿงช Test command:"
70
+ puts " curl -X POST http://localhost:8080/v1/chat/completions \\"
71
+ puts " -H 'Content-Type: application/json' \\"
72
+ puts ' -d \'{"model": "say-something-v2", "messages": [{"role": "user", "content": "hello"}]}\''
73
+ puts ""
74
+ puts "๐Ÿ’ก Try different questions to see automatic identity awareness:"
75
+ puts " - 'hello' or 'hi there' for context-aware introductions"
76
+ puts " - 'what are you?' or 'tell me about yourself'"
77
+ puts " - 'how long have you been running?'"
78
+ puts " - 'what can you do?' or 'what tools do you have?'"
79
+ puts " - 'what cluster are you in?'"
80
+ puts ""
81
+
82
+ LanguageOperator::Agent.run
83
+ end
File without changes