-
Notifications
You must be signed in to change notification settings - Fork 7
feat(runtime):增加可修改死循环次数以及自我纠正提示 #298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d7c1aac
feat(runtime):增加可修改死循环次数以及自我纠正提示
phantom5099 4098da8
fix(runtime,config): resolve PR review items and simplify streak hand…
xgopilot 319b303
refactor(runtime,config): address review feedback on streak handling
xgopilot 564e393
Merge pull request #15 from phantom5099/fork-pr-298-1776187797
phantom5099 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,7 @@ type persistedConfig struct { | |
| CurrentModel string `yaml:"current_model,omitempty"` | ||
| Shell string `yaml:"shell"` | ||
| ToolTimeoutSec int `yaml:"tool_timeout_sec,omitempty"` | ||
| Runtime RuntimeConfig `yaml:"runtime,omitempty"` | ||
| Context persistedContextConfig `yaml:"context,omitempty"` | ||
| Tools ToolsConfig `yaml:"tools,omitempty"` | ||
| Memo persistedMemoConfig `yaml:"memo,omitempty"` | ||
|
|
@@ -204,6 +205,7 @@ func parseCurrentConfig(data []byte, contextDefaults ContextConfig, memoDefaults | |
| CurrentModel: strings.TrimSpace(file.CurrentModel), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Shell: strings.TrimSpace(file.Shell), | ||
| ToolTimeoutSec: file.ToolTimeoutSec, | ||
| Runtime: file.Runtime, | ||
| Context: fromPersistedContextConfig(file.Context, contextDefaults), | ||
| Tools: file.Tools, | ||
| Memo: fromPersistedMemoConfig(file.Memo, memoDefaults), | ||
|
|
@@ -218,6 +220,7 @@ func marshalPersistedConfig(snapshot Config) ([]byte, error) { | |
| CurrentModel: snapshot.CurrentModel, | ||
| Shell: snapshot.Shell, | ||
| ToolTimeoutSec: snapshot.ToolTimeoutSec, | ||
| Runtime: snapshot.Runtime, | ||
| Context: newPersistedContextConfig(snapshot.Context), | ||
| Tools: snapshot.Tools, | ||
| Memo: newPersistedMemoConfig(snapshot.Memo), | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package config | ||
|
|
||
| import ( | ||
| "errors" | ||
| ) | ||
|
|
||
| const ( | ||
| DefaultMaxNoProgressStreak = 3 | ||
| ) | ||
|
|
||
| // RuntimeConfig 定义 runtime 层的可调参数。 | ||
| type RuntimeConfig struct { | ||
| MaxNoProgressStreak int `yaml:"max_no_progress_streak,omitempty"` | ||
| } | ||
|
|
||
| // defaultRuntimeConfig 返回 runtime 配置的静态默认值。 | ||
| func defaultRuntimeConfig() RuntimeConfig { | ||
| return RuntimeConfig{ | ||
| MaxNoProgressStreak: DefaultMaxNoProgressStreak, | ||
| } | ||
| } | ||
|
|
||
| // Clone 复制 runtime 配置,避免调用方共享可变状态。 | ||
| func (c RuntimeConfig) Clone() RuntimeConfig { | ||
| return c | ||
| } | ||
|
|
||
| // ApplyDefaults 在配置缺失或非法时回填默认阈值。 | ||
| func (c *RuntimeConfig) ApplyDefaults(defaults RuntimeConfig) { | ||
| if c == nil { | ||
| return | ||
| } | ||
| if c.MaxNoProgressStreak <= 0 { | ||
| c.MaxNoProgressStreak = defaults.MaxNoProgressStreak | ||
| } | ||
| } | ||
|
|
||
| // Validate 校验 runtime 配置是否满足最小约束。 | ||
| func (c RuntimeConfig) Validate() error { | ||
| if c.MaxNoProgressStreak <= 0 { | ||
| return errors.New("max_no_progress_streak must be greater than 0") | ||
| } | ||
| return nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package config | ||
|
|
||
| import "testing" | ||
|
|
||
| func TestRuntimeConfigClone(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| cfg := RuntimeConfig{MaxNoProgressStreak: 7} | ||
| cloned := cfg.Clone() | ||
| if cloned.MaxNoProgressStreak != 7 { | ||
| t.Fatalf("expected cloned MaxNoProgressStreak=7, got %d", cloned.MaxNoProgressStreak) | ||
| } | ||
| } | ||
|
|
||
| func TestRuntimeConfigApplyDefaults(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| defaults := RuntimeConfig{MaxNoProgressStreak: 3} | ||
|
|
||
| cfg := RuntimeConfig{MaxNoProgressStreak: 0} | ||
| cfg.ApplyDefaults(defaults) | ||
| if cfg.MaxNoProgressStreak != 3 { | ||
| t.Fatalf("expected defaulted MaxNoProgressStreak=3, got %d", cfg.MaxNoProgressStreak) | ||
| } | ||
|
|
||
| cfg = RuntimeConfig{MaxNoProgressStreak: 5} | ||
| cfg.ApplyDefaults(defaults) | ||
| if cfg.MaxNoProgressStreak != 5 { | ||
| t.Fatalf("expected existing MaxNoProgressStreak=5 to be preserved, got %d", cfg.MaxNoProgressStreak) | ||
| } | ||
|
|
||
| var nilCfg *RuntimeConfig | ||
| nilCfg.ApplyDefaults(defaults) | ||
| } | ||
|
|
||
| func TestRuntimeConfigValidate(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| if err := (RuntimeConfig{MaxNoProgressStreak: 1}).Validate(); err != nil { | ||
| t.Fatalf("expected valid config, got %v", err) | ||
| } | ||
|
|
||
| for _, bad := range []int{0, -1, -99} { | ||
| if err := (RuntimeConfig{MaxNoProgressStreak: bad}).Validate(); err == nil { | ||
| t.Fatalf("expected validation error for MaxNoProgressStreak=%d", bad) | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This introduces a new persisted/validated config surface (
runtime.max_no_progress_streak), but the config docs are not updated in this PR. Please update the configuration docs (fields, defaults, and example YAML) so implementation and docs stay in sync.