Class RequestContext
AgentExecutor.
This class encapsulates all the information an agent needs to process a request: the user's message, existing task state (for continuing conversations), configuration, and server call context. It's the primary way agents access request data.
Key Components
- Message: The user's input message with parts (text, images, etc.)
- Task: Existing task state for continuing conversations (null for new conversations)
- TaskId/ContextId: Identifiers for the task and conversation (auto-generated if not provided)
- Configuration: Request settings (blocking mode, push notifications, etc.)
- Related Tasks: Other tasks in the same conversation context
Common Usage Patterns
public void execute(RequestContext context, AgentEmitter emitter) {
// Check if this is a new conversation or continuation
Task existingTask = context.getTask();
if (existingTask == null) {
// New conversation - initialize
} else {
// Continuing conversation - access history
List<Message> history = existingTask.history();
}
// Extract user input
String userMessage = context.getUserInput("\n");
// Access configuration if needed
MessageSendConfiguration config = context.getConfiguration();
boolean returnImmediately = config != null && Boolean.TRUE.equals(config.returnImmediately());
// Process and respond...
}
Text Extraction Helper
ThegetUserInput(String) method is a convenient way to extract text from
message parts:
// Get all text parts joined with newlines
String text = context.getUserInput("\n");
// Get all text parts joined with spaces
String text = context.getUserInput(" ");
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionvoidattachRelatedTask(Task task) Attaches a related task to this context.@Nullable ServerCallContextReturns the server call context.@Nullable MessageSendConfigurationReturns the request configuration.Returns the conversation context identifier.@Nullable MessageReturns the user's message.Returns the request metadata.Returns other tasks in the same conversation context.@Nullable TaskgetTask()Returns the existing task state, if this is a continuation of a conversation.Returns the task identifier.@Nullable StringReturns the tenant identifier from the request parameters.Extracts all text content from the message and joins with the newline delimiter.getUserInput(@Nullable String delimiter) Extracts all text content from the message and joins with the specified delimiter.
-
Method Details
-
getTaskId
Returns the task identifier.This is auto-generated (UUID) by the builder if not provided by the client in the message parameters. This value is never null.
- Returns:
- the task ID (never null)
-
getContextId
Returns the conversation context identifier.Conversation contexts group related tasks together (e.g., multiple tasks in the same user session). This is auto-generated (UUID) by the builder if not provided by the client in the message parameters. This value is never null.
- Returns:
- the context ID (never null)
-
getTask
Returns the existing task state, if this is a continuation of a conversation.For new conversations, this is null. For continuing conversations, contains the full task state including history, artifacts, and status.
Common Pattern:
if (context.getTask() == null) { // New conversation - initialize state } else { // Continuing - access previous messages List<Message> history = context.getTask().history(); }- Returns:
- the existing task, or null if this is a new conversation
-
getRelatedTasks
Returns other tasks in the same conversation context.Useful for multi-task conversations where the agent needs to access state from related tasks.
- Returns:
- unmodifiable list of related tasks (empty if none)
-
getMessage
Returns the user's message.Contains the message parts (text, images, etc.) sent by the client. Use
getUserInput(String)for convenient text extraction.- Returns:
- the message, or null if not available
- See Also:
-
getConfiguration
Returns the request configuration.Contains settings like blocking mode, push notification config, etc.
- Returns:
- the configuration, or null if not provided
-
getMetadata
Returns the request metadata.- Returns:
- the metadata, or null if not available
-
getCallContext
Returns the server call context.Contains transport-specific information like authentication, headers, etc. Most agents don't need this.
- Returns:
- the call context, or null if not available
-
getTenant
Returns the tenant identifier from the request parameters.The tenant is used in multi-tenant environments to identify which customer or organization the request belongs to.
- Returns:
- the tenant identifier, or null if no params or tenant not set
-
getUserInput
Extracts all text content from the message and joins with the newline delimiter.This is a convenience method for getting text input from messages that may contain multiple text parts. Non-text parts (images, etc.) are ignored.
Examples:
// Join with newlines (common for multi-paragraph input) String text = context.getUserInput();- Returns:
- all text parts joined with newline, or empty string if no message
-
getUserInput
Extracts all text content from the message and joins with the specified delimiter.This is a convenience method for getting text input from messages that may contain multiple text parts. Non-text parts (images, etc.) are ignored.
Examples:
// Join with newlines (common for multi-paragraph input) String text = context.getUserInput(); // Join with spaces (common for single-line input) String text = context.getUserInput(" "); // Default delimiter is newline String text = context.getUserInput(null); // uses "\n"- Parameters:
delimiter- the string to insert between text parts (null defaults to "\n")- Returns:
- all text parts joined with delimiter, or empty string if no message
-
attachRelatedTask
Attaches a related task to this context.This is primarily used by the framework to populate related tasks after construction. Agent implementations should use
getRelatedTasks()to access related tasks.- Parameters:
task- the task to attach
-