Let agents cancel open questions; fix snapshots missing same-size edits
This commit is contained in:
@@ -124,10 +124,61 @@ func (m *Manager) ask(ctx context.Context, l *live, raw json.RawMessage) (string
|
||||
|
||||
m.snapshotSoon(l, api.SnapshotTriggerAskHuman)
|
||||
|
||||
cancel := fmt.Sprintf("If the human answers it some other way, such as in a chat message, withdraw it with cancel_question and question_id %q.", id)
|
||||
if *args.Blocking {
|
||||
return fmt.Sprintf("Question %s filed in the human's inbox. It is blocking: end your turn now. The answer will arrive as your next message.", id), nil
|
||||
return fmt.Sprintf("Question filed in the human's inbox. question_id: %s. It is blocking: end your turn now. The answer will arrive as your next message. %s", id, cancel), nil
|
||||
}
|
||||
return fmt.Sprintf("Question %s filed in the human's inbox. Continue with work that doesn't depend on it; the answer will arrive as a later message.", id), nil
|
||||
return fmt.Sprintf("Question filed in the human's inbox. question_id: %s. Continue with work that doesn't depend on it; the answer will arrive as a later message. %s", id, cancel), nil
|
||||
}
|
||||
|
||||
type cancelArgs struct {
|
||||
QuestionID string `json:"question_id"`
|
||||
}
|
||||
|
||||
func (m *Manager) cancelQuestionTool(l *live) mcp.Tool {
|
||||
return mcp.Tool{
|
||||
Name: "cancel_question",
|
||||
Description: "Withdraw a question you asked with ask_human that is still waiting in the human's inbox, " +
|
||||
"for example because the human answered it in a chat message instead. It is removed from the inbox and no answer to it will arrive.",
|
||||
InputSchema: json.RawMessage(`{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"question_id": {"type": "string", "description": "The question_id ask_human returned."}
|
||||
},
|
||||
"required": ["question_id"]
|
||||
}`),
|
||||
Handler: func(ctx context.Context, raw json.RawMessage) (string, error) {
|
||||
return m.cancelQuestion(ctx, l, raw)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) cancelQuestion(ctx context.Context, l *live, raw json.RawMessage) (string, error) {
|
||||
args := cancelArgs{}
|
||||
err := json.Unmarshal(raw, &args)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("malformed cancel_question call: %w", err)
|
||||
}
|
||||
|
||||
item, err := m.store.GetInboxItem(ctx, args.QuestionID)
|
||||
if errors.Is(err, store.ErrNotFound) {
|
||||
return "", fmt.Errorf("question_id %s does not exist", args.QuestionID)
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if item.AgentSessionId != l.id || item.Kind != api.Question {
|
||||
return "", fmt.Errorf("question_id %s is not a question you asked", args.QuestionID)
|
||||
}
|
||||
|
||||
err = m.store.WithdrawItem(ctx, item.Id)
|
||||
if errors.Is(err, store.ErrNotOpen) {
|
||||
return "", fmt.Errorf("question %s is already %s; nothing was cancelled", item.Id, item.State)
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return fmt.Sprintf("Question %s withdrawn from the human's inbox.", item.Id), nil
|
||||
}
|
||||
|
||||
func (m *Manager) validateAsk(ctx context.Context, l *live, args askArgs) error {
|
||||
|
||||
Reference in New Issue
Block a user