Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions coderd/x/chatd/chatloop/chatloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,6 @@ type ExecuteLocalToolsOptions struct {
Clock quartz.Clock
}

// ToolExecutionOutcome is the durable tool-result content from one batch.
type ToolExecutionOutcome struct {
Step PersistedStep
}

// GenerateCompactionOptions configures one context compaction call.
type GenerateCompactionOptions struct {
Model fantasy.LanguageModel
Expand Down Expand Up @@ -562,7 +557,7 @@ func contentFilterError(provider string, metadata fantasy.ProviderMetadata) erro

// ExecuteLocalTools runs local tool calls and returns durable tool results. It
// does not retry or persist.
func ExecuteLocalTools(ctx context.Context, opts ExecuteLocalToolsOptions) (ToolExecutionOutcome, error) {
func ExecuteLocalTools(ctx context.Context, opts ExecuteLocalToolsOptions) (PersistedStep, error) {
if opts.Metrics == nil {
opts.Metrics = NopMetrics()
}
Expand All @@ -584,7 +579,7 @@ func ExecuteLocalTools(ctx context.Context, opts ExecuteLocalToolsOptions) (Tool
// without capturing the publisher at construction time.
ctx = WithMessagePartPublisher(ctx, opts.PublishMessagePart)
if ctx.Err() != nil {
return ToolExecutionOutcome{}, ctx.Err()
return PersistedStep{}, ctx.Err()
}

localCalls := make([]fantasy.ToolCallContent, 0, len(opts.ToolCalls))
Expand All @@ -594,7 +589,7 @@ func ExecuteLocalTools(ctx context.Context, opts ExecuteLocalToolsOptions) (Tool
}
}
if len(localCalls) == 0 {
return ToolExecutionOutcome{}, nil
return PersistedStep{}, nil
}

var result stepResult
Expand All @@ -616,12 +611,12 @@ func ExecuteLocalTools(ctx context.Context, opts ExecuteLocalToolsOptions) (Tool
result.content = append(result.content, tr)
}
if ctx.Err() != nil {
return ToolExecutionOutcome{}, ctx.Err()
return PersistedStep{}, ctx.Err()
}
return ToolExecutionOutcome{Step: PersistedStep{
return PersistedStep{
Content: result.content,
ToolResultCreatedAt: result.toolResultCreatedAt,
}}, nil
}, nil
}

maxResultBytes := toolResultByteBudget(opts.ContextLimit)
Expand Down Expand Up @@ -650,15 +645,15 @@ func ExecuteLocalTools(ctx context.Context, opts ExecuteLocalToolsOptions) (Tool
},
)
if ctx.Err() != nil {
return ToolExecutionOutcome{}, ctx.Err()
return PersistedStep{}, ctx.Err()
}
for _, tr := range toolResults {
result.content = append(result.content, tr)
}
return ToolExecutionOutcome{Step: PersistedStep{
return PersistedStep{
Content: result.content,
ToolResultCreatedAt: result.toolResultCreatedAt,
}}, nil
}, nil
}

// prepareMessagesForRequest applies the prompt preparation pipeline used
Expand Down
13 changes: 7 additions & 6 deletions coderd/x/chatd/generation.go
Original file line number Diff line number Diff line change
Expand Up @@ -858,7 +858,7 @@ func (s *taskStarter) executeLocalTools(
provider = prepared.Model.Provider()
modelName = prepared.Model.ModelID()
}
var outcome chatloop.ToolExecutionOutcome
var outcome chatloop.PersistedStep
var spawnDispatchErr error
if len(allowed) > 0 {
outcome, err = chatloop.ExecuteLocalTools(ctx, chatloop.ExecuteLocalToolsOptions{
Expand Down Expand Up @@ -886,18 +886,19 @@ func (s *taskStarter) executeLocalTools(
// the tool run; its failure surfaces as a tool result error. The
// step still commits so a sibling tool that already ran keeps its
// result and is not re-executed, and the turn fails afterwards.
if hookErr := chathooks.DispatchFailureFromResults(outcome.Step.Content); hookErr != nil {
if hookErr := chathooks.DispatchFailureFromResults(outcome.Content); hookErr != nil {
spawnDispatchErr = chathooks.GenerationDispatchError(agenthooks.EventUserPromptSubmit, hookErr)
}
}
postResults, postDispatchErr := s.server.hooks.PostToolUseResults(ctx, chathooks.ChatFor(prepared.Chat, input.hookTurnID()), outcome.Step.Content)
postResults, postDispatchErr := s.server.hooks.PostToolUseResults(ctx, chathooks.ChatFor(prepared.Chat, input.hookTurnID()), outcome.Content)
for _, result := range denied {
outcome.Step.Content = append(outcome.Step.Content, result)
outcome.Content = append(outcome.Content, result)
}
chathooks.RestoreToolCallOrder(outcome.Step.Content, decision.localToolCalls)
chathooks.RestoreToolCallOrder(outcome.Content, decision.localToolCalls)
step := stepDataFromPersisted(outcome)
messages, err := buildCommitStepMessages(buildCommitStepMessagesInput{
modelConfigID: prepared.ModelConfigID,
step: stepDataFromPersisted(outcome.Step),
step: step,
toolNameToConfigID: prepared.ToolNameToConfigID,
logger: s.opts.Logger,
contentVersion: chatprompt.CurrentContentVersion,
Expand Down
Loading