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

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

Loading…
Cancel
Save