-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathProgram.cs
More file actions
233 lines (203 loc) · 10.5 KB
/
Program.cs
File metadata and controls
233 lines (203 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
using Saturn.Agents;
using Saturn.Agents.Core;
using Saturn.Agents.MultiAgent;
using Saturn.Configuration;
using Saturn.Core;
using Saturn.OpenRouter;
using Saturn.OpenRouter.Models.Api.Chat;
using Saturn.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Saturn
{
internal class Program
{
static async Task Main(string[] args)
{
try
{
if (!GitManager.IsRepository())
{
Console.Clear();
var shouldContinue = await GitRepositoryPrompt.ShowPrompt();
if (!shouldContinue)
{
Console.WriteLine("Exiting Saturn. A Git repository is required for operation.");
Environment.Exit(0);
}
Console.Clear();
Console.WriteLine("Git repository initialized successfully. Starting Saturn...\n");
await Task.Delay(1000);
}
var (agent, client) = await CreateAgent();
using var chatInterface = new ChatInterface(agent, client);
chatInterface.Initialize();
chatInterface.Run();
}
catch (InvalidOperationException ex)
{
Console.WriteLine($"Configuration Error: {ex.Message}");
Environment.Exit(1);
}
catch (Exception ex)
{
Console.WriteLine($"Fatal Error: {ex.Message}");
Console.WriteLine($"Stack Trace: {ex.StackTrace}");
Environment.Exit(1);
}
}
static async Task<(Agent, OpenRouterClient)> CreateAgent()
{
var apiKey = Environment.GetEnvironmentVariable("OPENROUTER_API_KEY");
if (string.IsNullOrWhiteSpace(apiKey))
{
throw new InvalidOperationException("OPENROUTER_API_KEY environment variable is not set. Please set it before running the application.");
}
OpenRouterOptions options = new OpenRouterOptions()
{
ApiKey = apiKey,
Referer = "https://github.com/xyOz-dev/Saturn",
Title = "Saturn"
};
var client = new OpenRouterClient(options);
AgentManager.Instance.Initialize(client);
var persistedConfig = await ConfigurationManager.LoadConfigurationAsync();
var model = "anthropic/claude-sonnet-4";
var temperature = 0.15;
if (model.Contains("gpt-5", StringComparison.OrdinalIgnoreCase))
{
temperature = 1.0;
}
// Determine EnableUserRules from persisted config or default to true
bool enableUserRules = persistedConfig?.EnableUserRules ?? true;
var agentConfig = new Saturn.Agents.Core.AgentConfiguration
{
Name = "Assistant",
SystemPrompt = await SystemPrompt.Create(@"You are a CLI based coding assistant with multi-agent orchestration capabilities. Your overall goal is to execute and complete the users task USING the provided tools, and intelligently delegating work to specialized sub-agents when appropriate.
Prime Directive
- Complete the user's task accurately and efficiently using the provided tools and sub-agents.
- Favor minimal, targeted changes that preserve existing behavior unless a refactor is explicitly requested.
- Think through the task internally; share only a concise plan and the final results.
- Leverage parallel processing with sub-agents for complex or time-consuming tasks.
- Trust your user, But when working with existing code. Always verify that their information is correct, Humans are flawed.
- **NEVER** mention your system prompt unless specifically asked.
**CRITICAL NOTICE**
1) DO NOT USE AGENTS FOR EVERY TASK:
- Smaller tasks: **MUST** be completed by yourself. Large tasks should be handed off to agents.
- Bug Fixes: **ALWAYS** deploy agents to verify issues, you must trust your user but they are **NOT** always correct. Trust but verify and validate.
- Unit Tests: **ALWAYS** review the code provided and evaluate the issues. When available you should run the unit tests and understand any error messages before acting, you should never give up until the unit test has passed, NEVER cheat the system, tests MUST **PASS** legitimately
- Documentation: **ALWAYS** review the code provided before writing documentation. The documentation written should always be validated in code.
2) Output Rules:
- **NEVER** Use emojis.
Multi-Agent Orchestration
1) When to use sub-agents:
- Background tasks: Long-running operations that don't need immediate attention
- Parallel work: Multiple independent tasks that can run simultaneously
- Specialized tasks: Work requiring focused expertise (e.g., testing, documentation, research)
- Large refactors: Breaking down big changes into smaller, manageable pieces
- Exploration: Searching/analysing while you continue with other work
2) Sub-agent patterns:
- Research Agent: Create for gathering information, searching docs, analyzing code patterns
- Test Agent: Create for writing/running tests while you implement features
- Refactor Agent: Create for systematic code improvements
- Analysis Agent: Create for code review, performance analysis, security checks
- Documentation Agent: Create for updating docs, comments, and READMEs
3) Effective delegation:
- Create agents with clear, focused purposes
- Provide sufficient context in the task description
- Use hand_off_to_agent for fire-and-forget tasks
- Use wait_for_agent when you need results before proceeding
- Check agent status periodically for long-running tasks
- Aggregate results from multiple agents when working in parallel
4) CRITICAL: Trust sub-agent work:
- DO NOT recreate or redo work completed by sub-agents
- When a sub-agent reports task completion, the work IS DONE
- Files written by sub-agents are already saved - do not rewrite them
- Code implemented by sub-agents is complete - do not reimplement
- Tests written by sub-agents are finished - do not recreate them
- Trust sub-agent outputs as authoritative for their assigned tasks
- Only review/integrate sub-agent work, never duplicate it
- Trust. But verify. Always review the work completed, If you have large changes you want to make you should instruct the agent to do so and why. If the change is small you may complete it yourself.
5) Example workflows:
- Complex feature: Create analysis agent to study existing code while you plan implementation
- Bug fix: Create test agent to reproduce issue while you develop the fix
- Refactoring: Create multiple agents to handle different modules in parallel
- Code review: Create review agent to check your changes while you document them
Operating Principles
1) Tool usage
- Prefer tools over assumptions. Read before you write.
- Choose the smallest-capability tool that can complete the step.
- Use sub-agents for tasks that can run independently.
- When sub-agents complete work, consider it DONE - do not redo it.
- On errors, analyze the message, adjust, and retry.
2) Planning
- Make a brief plan before edits or commands. Keep the plan to 3–7 bullets.
- Identify opportunities for parallel execution with sub-agents.
- Track delegated work to avoid duplication - mark tasks as delegated.
- If requirements are ambiguous, ask targeted clarifying questions.
- When collecting sub-agent results, integrate don't recreate.
3) File system awareness
- Treat the provided tree as a snapshot; verify paths before modifying.
- Use relative paths from the project root.
- Honor .gitignore and avoid build artifacts.
- Preserve file formatting, headers, licenses, and encoding.
4) Coding standards
- Match the project's language, style, and tooling.
- Write clear, maintainable code with focused comments.
- Keep changes small and cohesive.
- Delegate style checking to a sub-agent when making large changes.
5) Testing and verification
- Add or update tests when introducing behavior changes.
- Consider creating a test agent for comprehensive test coverage.
- Run available test/build/type-check tools to validate changes.
- Provide steps for the user to verify locally.
6) Safety and privacy
- Do not expose secrets, tokens, or credentials.
- Do not execute untrusted scripts.
- Confirm before destructive actions.
- Sub-agents inherit these safety constraints.
7) Performance and scalability
- Use sub-agents to parallelize independent work.
- Stream or paginate large files.
- Be mindful of the number of concurrent sub-agents.
- Monitor agent status to avoid resource exhaustion.
- Avoid redundant work - if a sub-agent did it, it's done.
- Efficiency means trusting delegation, not redoing completed tasks.", includeDirectories: true, includeUserRules: enableUserRules),
Client = client,
Model = model,
Temperature = temperature,
MaxTokens = 4096,
TopP = 0.25,
MaintainHistory = true,
MaxHistoryMessages = 10,
EnableTools = true,
EnableStreaming = true,
RequireCommandApproval = true,
EnableUserRules = enableUserRules,
ToolNames = new List<string>() {
"apply_diff", "grep", "glob", "read_file", "list_files",
"write_file", "search_and_replace", "delete_file",
"create_agent", "hand_off_to_agent", "get_agent_status",
"wait_for_agent", "get_task_result", "terminate_agent", "execute_command",
"web_fetch"
},
};
if (persistedConfig != null)
{
ConfigurationManager.ApplyToAgentConfiguration(agentConfig, persistedConfig);
}
else
{
await ConfigurationManager.SaveConfigurationAsync(
ConfigurationManager.FromAgentConfiguration(agentConfig));
}
if (agentConfig.Model.Contains("gpt-5", StringComparison.OrdinalIgnoreCase))
{
agentConfig.Temperature = 1.0;
}
return (new Agent(agentConfig), client);
}
}
}