refactor: use tool package interrupt APIs in follow_up_tool and review_edit_wrapper

- follow_up_tool.go: use tool.GetInterruptState, tool.GetResumeContext, tool.StatefulInterrupt
- review_edit_wrapper.go: use tool.GetInterruptState, tool.GetResumeContext, tool.StatefulInterrupt
- Remove ToolCallID from ReviewEditInfo (compose.GetToolCallID no longer used)
- Remove compose import from both files

Change-Id: I9fee8a8ef93a5b3eab4700c0850f6dce220e5f98
drew/english
shentong.martin 4 months ago committed by shentongmartin
parent f7ed18dd7e
commit 44e0085eae

@ -24,7 +24,6 @@ import (
"github.com/cloudwego/eino/components/tool" "github.com/cloudwego/eino/components/tool"
"github.com/cloudwego/eino/components/tool/utils" "github.com/cloudwego/eino/components/tool/utils"
"github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema" "github.com/cloudwego/eino/schema"
) )
@ -59,30 +58,26 @@ func init() {
} }
func FollowUp(ctx context.Context, input *FollowUpToolInput) (string, error) { func FollowUp(ctx context.Context, input *FollowUpToolInput) (string, error) {
wasInterrupted, _, storedState := compose.GetInterruptState[*FollowUpState](ctx) wasInterrupted, _, storedState := tool.GetInterruptState[*FollowUpState](ctx)
if !wasInterrupted { if !wasInterrupted {
// First invocation: parse input, create info/state, and interrupt.
info := &FollowUpInfo{Questions: input.Questions} info := &FollowUpInfo{Questions: input.Questions}
state := &FollowUpState{Questions: input.Questions} state := &FollowUpState{Questions: input.Questions}
return "", compose.StatefulInterrupt(ctx, info, state) return "", tool.StatefulInterrupt(ctx, info, state)
} }
// Resume flow: check if we are the target and get the user's answer. isResumeTarget, hasData, resumeData := tool.GetResumeContext[*FollowUpInfo](ctx)
isResumeTarget, hasData, resumeData := compose.GetResumeContext[*FollowUpInfo](ctx)
if !isResumeTarget { if !isResumeTarget {
// Not for us. Re-interrupt with the same questions from the stored state.
info := &FollowUpInfo{Questions: storedState.Questions} info := &FollowUpInfo{Questions: storedState.Questions}
return "", compose.StatefulInterrupt(ctx, info, storedState) return "", tool.StatefulInterrupt(ctx, info, storedState)
} }
if !hasData || resumeData.UserAnswer == "" { if !hasData || resumeData.UserAnswer == "" {
return "", fmt.Errorf("tool resumed without a user answer") return "", fmt.Errorf("tool resumed without a user answer")
} }
// Success. The tool's output is the user's answer.
return resumeData.UserAnswer, nil return resumeData.UserAnswer, nil
} }

@ -21,7 +21,6 @@ import (
"fmt" "fmt"
"github.com/cloudwego/eino/components/tool" "github.com/cloudwego/eino/components/tool"
"github.com/cloudwego/eino/compose"
"github.com/cloudwego/eino/schema" "github.com/cloudwego/eino/schema"
) )
@ -29,7 +28,6 @@ import (
type ReviewEditInfo struct { type ReviewEditInfo struct {
ToolName string ToolName string
ArgumentsInJSON string ArgumentsInJSON string
ToolCallID string
ReviewResult *ReviewEditResult ReviewResult *ReviewEditResult
} }
@ -69,21 +67,19 @@ func (i InvokableReviewEditTool) InvokableRun(ctx context.Context, argumentsInJS
return "", err return "", err
} }
wasInterrupted, _, storedArguments := compose.GetInterruptState[string](ctx) wasInterrupted, _, storedArguments := tool.GetInterruptState[string](ctx)
if !wasInterrupted { // Initial invocation, interrupt for review. if !wasInterrupted {
return "", compose.StatefulInterrupt(ctx, &ReviewEditInfo{ return "", tool.StatefulInterrupt(ctx, &ReviewEditInfo{
ToolName: toolInfo.Name, ToolName: toolInfo.Name,
ArgumentsInJSON: argumentsInJSON, ArgumentsInJSON: argumentsInJSON,
ToolCallID: compose.GetToolCallID(ctx),
}, argumentsInJSON) }, argumentsInJSON)
} }
isResumeTarget, hasData, data := compose.GetResumeContext[*ReviewEditInfo](ctx) isResumeTarget, hasData, data := tool.GetResumeContext[*ReviewEditInfo](ctx)
if !isResumeTarget { // Not for us, re-interrupt. if !isResumeTarget {
return "", compose.StatefulInterrupt(ctx, &ReviewEditInfo{ return "", tool.StatefulInterrupt(ctx, &ReviewEditInfo{
ToolName: toolInfo.Name, ToolName: toolInfo.Name,
ArgumentsInJSON: storedArguments, ArgumentsInJSON: storedArguments,
ToolCallID: compose.GetToolCallID(ctx),
}, storedArguments) }, storedArguments)
} }
if !hasData || data.ReviewResult == nil { if !hasData || data.ReviewResult == nil {

Loading…
Cancel
Save