Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:A2aproject A2a java RequestContext

From Leeroopedia
Knowledge Sources
Domains Server, Agent_Execution, Request_Handling
Last Updated 2026-10-30 00:00 GMT

Overview

Concrete container for request parameters and task state provided to AgentExecutor, encapsulating user messages, existing task history, configuration, and server call context.

Description

The RequestContext class encapsulates all the information an agent needs to process a request: the user's message (MessageSendParams), existing task state for continuing conversations (Task, null for new conversations), task and context identifiers (auto-generated UUIDs if not provided), configuration (MessageSendConfiguration), related tasks in the same conversation context, and the ServerCallContext. It provides the getUserInput(String) helper to extract text from message parts. The class uses a Builder pattern for construction with ID generation and validation.

Usage

  • Agent execution: Passed as the first argument to AgentExecutor.execute() — agents read user input and task history from it
  • Continuation detection: Agents check `getTask() == null` to distinguish new vs. continuing conversations
  • Text extraction: Use `getUserInput("\n")` to concatenate all text parts from the user message

Code Reference

Source Location

  • Repository: a2a-java
  • File: `server-common/src/main/java/org/a2aproject/sdk/server/agentexecution/RequestContext.java`
  • Lines: L76-454

Signature

public class RequestContext {
    private RequestContext(@Nullable MessageSendParams params, String taskId,
            String contextId, @Nullable String tenant, @Nullable Task task,
            List<Task> relatedTasks, @Nullable ServerCallContext callContext);

    public String getTaskId();
    public String getContextId();
    public @Nullable String getTenant();
    public @Nullable Task getTask();
    public @Nullable Message getMessage();
    public @Nullable MessageSendConfiguration getConfiguration();
    public List<Task> getRelatedTasks();
    public @Nullable ServerCallContext getCallContext();
    public @Nullable String getUserInput(String separator);

    // Builder pattern
    public static class Builder {
        public Builder(MessageSendParams params, TaskStore taskStore);
        public Builder taskId(String taskId);
        public Builder contextId(String contextId);
        public RequestContext build();
    }
}

Import

import org.a2aproject.sdk.server.agentexecution.RequestContext;

I/O Contract

Inputs

Name Type Required Description
params MessageSendParams No (null for cancel) User message parameters
taskId String Yes (auto-generated) Task identifier
contextId String Yes (auto-generated) Conversation context identifier
tenant String No Tenant identifier for multitenancy
task Task No Existing task state (null for new)
relatedTasks List<Task> Yes (can be empty) Other tasks in same context
callContext ServerCallContext No Server request context

Outputs

Name Type Description
getTaskId() String Auto-generated or provided task ID
getTask() Task (nullable) Existing task or null for new conversations
getMessage() Message (nullable) User's input message
getUserInput() String (nullable) Concatenated text parts
getRelatedTasks() List<Task> Tasks in same context

Usage Examples

Agent Executor Using RequestContext

import org.a2aproject.sdk.server.agentexecution.RequestContext;
import org.a2aproject.sdk.server.tasks.AgentEmitter;

public class MyAgent implements AgentExecutor {
    @Override
    public void execute(RequestContext context, AgentEmitter emitter) {
        // Extract user input text
        String userInput = context.getUserInput("\n");

        // Check if new or continuing conversation
        Task existingTask = context.getTask();
        if (existingTask == null) {
            // New conversation
            emitter.emitStatusUpdate(TaskState.WORKING);
        } else {
            // Continuing - access history
            List<Message> history = existingTask.history();
        }

        // Process and respond
        emitter.emitMessage(A2A.toAgentMessage("Hello! " + userInput));
        emitter.emitStatusUpdate(TaskState.COMPLETED);
    }
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment