language-operator 0.1.70 โ 0.1.80
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/Gemfile.lock +1 -1
- data/components/agent/Gemfile +1 -1
- data/components/tool/Gemfile +1 -1
- data/docs/persona-driven-system-prompts.md +346 -0
- data/examples/basic_agent_with_default_chat.rb +99 -0
- data/examples/chat_endpoint_agent.rb +7 -19
- data/examples/identity_aware_chat_agent.rb +83 -0
- data/examples/ux_helpers_demo.rb +0 -0
- data/lib/language_operator/agent/base.rb +12 -7
- data/lib/language_operator/agent/execution_state.rb +92 -0
- data/lib/language_operator/agent/metadata_collector.rb +222 -0
- data/lib/language_operator/agent/prompt_builder.rb +282 -0
- data/lib/language_operator/agent/web_server.rb +610 -21
- data/lib/language_operator/agent.rb +34 -25
- data/lib/language_operator/dsl/agent_definition.rb +3 -53
- data/lib/language_operator/dsl/chat_endpoint_definition.rb +112 -2
- data/lib/language_operator/templates/schema/agent_dsl_openapi.yaml +1 -1
- data/lib/language_operator/templates/schema/agent_dsl_schema.json +1 -1
- data/lib/language_operator/version.rb +1 -1
- data/synth/003/Makefile +6 -0
- metadata +9 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2e6aa13623ea7f320f5be1ffbf252aa2320fdcb951c658905c43476f63f30a2a
|
|
4
|
+
data.tar.gz: a2136ce8803e111628610981f33b3ae5c9332662b97aaf36f483b0a144403e2a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f68216fc87b0d38c29ac06d2d133dba4f5cbef23a4a8a848a91205c3545e4757123fccbc7a51f7e2e7940d6e7168c76af3cd6ab380f52ae7cc520256d4d1d352
|
|
7
|
+
data.tar.gz: 0c4c40b6e2c813e9b0dd4b2dcc2cd9a8083ae56cbbd9b26512298f640f176e8d28ff872a4479a100ff7be58b80c3b949f1dd40925691573dc3a1ed11a834f7c7
|
data/Gemfile.lock
CHANGED
data/components/agent/Gemfile
CHANGED
data/components/tool/Gemfile
CHANGED
|
@@ -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
|
|
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
|
-
#
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
data/examples/ux_helpers_demo.rb
CHANGED
|
File without changes
|
|
@@ -107,24 +107,29 @@ module LanguageOperator
|
|
|
107
107
|
@executor.run_loop
|
|
108
108
|
end
|
|
109
109
|
|
|
110
|
-
# Run in scheduled mode (
|
|
110
|
+
# Run in scheduled mode (standby - waits for HTTP triggers)
|
|
111
111
|
#
|
|
112
112
|
# @return [void]
|
|
113
113
|
def run_scheduled
|
|
114
|
-
logger.info('Agent running in scheduled mode
|
|
114
|
+
logger.info('Agent running in scheduled mode (standby) - waiting for HTTP triggers')
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
116
|
+
require_relative 'web_server'
|
|
117
|
+
@web_server = WebServer.new(self)
|
|
118
|
+
@web_server.register_execute_endpoint(self, nil)
|
|
119
|
+
@web_server.register_workspace_endpoints(self)
|
|
120
|
+
@web_server.start
|
|
120
121
|
end
|
|
121
122
|
|
|
122
|
-
# Run in reactive mode (HTTP server)
|
|
123
|
+
# Run in reactive mode (standby - HTTP server with execute endpoint)
|
|
123
124
|
#
|
|
124
125
|
# @return [void]
|
|
125
126
|
def run_reactive
|
|
127
|
+
logger.info('Agent running in reactive mode (standby) - web server only')
|
|
128
|
+
|
|
126
129
|
require_relative 'web_server'
|
|
127
130
|
@web_server = WebServer.new(self)
|
|
131
|
+
@web_server.register_execute_endpoint(self, nil) # Enable /api/v1/execute endpoint
|
|
132
|
+
@web_server.register_workspace_endpoints(self)
|
|
128
133
|
@web_server.start
|
|
129
134
|
end
|
|
130
135
|
|