Submit Interactive Replies

When an agent task enters the input-required state, inspect the pending questions and input request identifier in the task status message, then submit structured answers by question ID and continue tracking the same task.

Task flow

Task ID in input-required state
              │
              ▼
  Read tool input requests from status message
              │
              ▼
  Extract inputRequestId and question IDs
              │
              ▼
  Submit structured answers and recheck task state

Prerequisites

  1. Complete the endpoint, personal access token, and workspace setup in Use the SDK.

  2. Obtain the agent ID that owns the task by following Discover and Select Agents.

  3. Obtain a task ID currently in the input-required state from Invoke Agents and Track Tasks.

Set the agent ID and pending task ID in your terminal:

export AGENT_ID='<agent-id>'
export AGENT_TASK_ID='<task-id-in-input-required-state>'

Read pending questions

Run the code below to fetch the task’s current status message, filter structured tool input requests (type equal to "moi.tool.call" with a nonempty inputRequestId), and print each input request ID and question list.

import json
import os
import uuid

import moi_product_sdk as sdk

client = sdk.new_with_personal_access_token(
    os.environ["PRODUCT_API_BASE_URL"],
    os.environ["PRODUCT_API_KEY"],
)
workspace = client.workspace(os.environ["WORKSPACE_ID"])
agent = workspace.agent_by_id(os.environ["AGENT_ID"])

task_id = os.environ["AGENT_TASK_ID"]
task = sdk.agent_a2a_payload(agent.get_task(sdk.AgentTaskRequest(task_id)))
if task.get("id") != task_id or task.get("status", {}).get("state") != "input-required":
    raise RuntimeError("Task is not waiting for input")

parts = task.get("status", {}).get("message", {}).get("parts", [])
requests = [
    part.get("data", {})
    for part in parts
    if part.get("kind") == "data"
    and part.get("data", {}).get("type") == "moi.tool.call"
    and part.get("data", {}).get("inputRequestId")
]
for req in requests:
    print("inputRequestId:", req["inputRequestId"])
    print(
        "questions:",
        json.dumps(req.get("arguments", {}).get("questions", []), ensure_ascii=False),
    )
package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"
	"time"

	sdk "github.com/matrixorigin/matrixflow/sdk/go-sdk"
)

func main() {
	ctx := context.Background()
	client, err := sdk.NewWithPersonalAccessToken(
		os.Getenv("PRODUCT_API_BASE_URL"),
		os.Getenv("PRODUCT_API_KEY"),
	)
	if err != nil {
		panic(err)
	}
	defer client.Close()

	workspace, err := client.Workspace(os.Getenv("WORKSPACE_ID"))
	if err != nil {
		panic(err)
	}
	agent, err := workspace.AgentByID(os.Getenv("AGENT_ID"))
	if err != nil {
		panic(err)
	}

	taskID := os.Getenv("AGENT_TASK_ID")
	current, err := agent.GetTask(ctx, sdk.AgentTaskRequest{TaskID: taskID})
	if err != nil {
		panic(err)
	}
	task, err := sdk.AgentA2APayload(current)
	if err != nil {
		panic(err)
	}
	status, _ := task["status"].(map[string]any)
	if task["id"] != taskID || status["state"] != "input-required" {
		panic("Task is not waiting for input")
	}

	message, _ := status["message"].(map[string]any)
	parts, _ := message["parts"].([]any)
	for _, part := range parts {
		value, _ := part.(map[string]any)
		data, _ := value["data"].(map[string]any)
		if value["kind"] != "data" || data["type"] != "moi.tool.call" {
			continue
		}
		reqID, _ := data["inputRequestId"].(string)
		if reqID == "" {
			continue
		}
		arguments, _ := json.Marshal(data["arguments"])
		fmt.Println("inputRequestId:", reqID)
		fmt.Println("questions:", string(arguments))
	}
	_ = time.Now
}

Submit interactive answers

Prepare a local answers.json file matching the question list printed above. Each top-level key must match a real question id, with its selected or entered values placed in answers (report_scope below is an illustrative question ID):

{
  "report_scope": {
    "answers": [
      "Current quarter"
    ]
  }
}

Set the target input request ID and answers file path, then continue with the same agent handle to submit the answers and inspect the updated task state and artifacts:

export INPUT_REQUEST_ID='<inputRequestId-printed-above>'
export ANSWERS_FILE='answers.json'
request_id = os.environ["INPUT_REQUEST_ID"]
if not any(req["inputRequestId"] == request_id for req in requests):
    raise RuntimeError("Selected inputRequestId is not pending on this task")

with open(os.environ["ANSWERS_FILE"], encoding="utf-8") as source:
    answers = json.load(source)

params = {
    "taskId": task_id,
    "requestId": request_id,
    "answers": answers,
}
result = agent.a2a(
    sdk.A2ARequest("matrixflow/input.submit", id_=str(uuid.uuid4()), params=params)
)
payload = sdk.agent_a2a_payload(result)
if payload.get("id") != task_id:
    raise RuntimeError("Response does not match the original task ID")

print("task_id:", payload.get("id"))
print("contextId:", payload.get("contextId"))
print("state:", payload.get("status", {}).get("state"))
for artifact in payload.get("artifacts", []):
    print("artifactId:", artifact.get("artifactId"))
    print("parts:", json.dumps(artifact.get("parts", []), ensure_ascii=False))
requestID := os.Getenv("INPUT_REQUEST_ID")
raw, err := os.ReadFile(os.Getenv("ANSWERS_FILE"))
if err != nil {
	panic(err)
}
var answers map[string]any
if err := json.Unmarshal(raw, &answers); err != nil {
	panic(err)
}

params, err := json.Marshal(map[string]any{
	"taskId":    taskID,
	"requestId": requestID,
	"answers":   answers,
})
if err != nil {
	panic(err)
}

result, err := agent.A2A(ctx, sdk.A2ARequest{
	JSONRPC: "2.0",
	ID:      fmt.Sprintf("submit-%d", time.Now().UnixNano()),
	Method:  sdk.A2AMethodInputSubmit,
	Params:  params,
})
if err != nil {
	panic(err)
}
payload, err := sdk.AgentA2APayload(result)
if err != nil {
	panic(err)
}
if payload["id"] != taskID {
	panic("Response does not match the original task ID")
}

fmt.Println("task_id:", payload["id"], "contextId:", payload["contextId"])
nextStatus, _ := payload["status"].(map[string]any)
fmt.Println("state:", nextStatus["state"])
artifacts, _ := json.Marshal(payload["artifacts"])
fmt.Println("artifacts:", string(artifacts))

Limitations and notes

  • Submitting answers confirms input acceptance; if the returned state remains submitted or working, continue querying the original task ID until it reaches a terminal state.

  • When a status message data part has type equal to "moi.provider_interaction.required", reply via message/send with a data part of type: "moi.provider_interaction.respond" carrying that interaction’s requestId, target, and payload (or cancelled: true without payload); matrixflow/input.submit applies only to "moi.input_request" interactions.

  • Restrict permissions on local files containing sensitive answers and keep them out of public logs and version control; if the task enters another interaction round, read the latest inputRequestId and questions again.

Next steps

Last updated on