Interface Agent.StreamEffect.Builder

Enclosing interface:
Agent.StreamEffect

public static interface Agent.StreamEffect.Builder
Construct the effect for token streaming that is returned by the message handler.
  • Method Details

    • model

      Define the AI model (LLM) to use. If undefined, the model is defined by the default configuration in akka.javasdk.agent.model-provider
    • systemMessage

      Agent.StreamEffect.Builder systemMessage(String message)
      Provides system-level instructions to the AI model that defines its behavior and context. The system message acts as a foundational prompt that establishes the AI's role, constraints, and operational parameters. It is processed before user messages and helps maintain consistent behavior throughout the interaction.
    • systemMessageFromTemplate

      Agent.StreamEffect.Builder systemMessageFromTemplate(String templateId)
      Create a system message from a template. Call @PromptTemplate before to initiate or update template value.

      Provides system-level instructions to the AI model that defines its behavior and context. The system message acts as a foundational prompt that establishes the AI's role, constraints, and operational parameters. It is processed before user messages and helps maintain consistent behavior throughout the interaction.

      Parameters:
      templateId - the id of the template to use
    • systemMessageFromTemplate

      Agent.StreamEffect.Builder systemMessageFromTemplate(String templateId, Object... args)
      Create a system message from a template. Call @PromptTemplate before to initiate or update template value. Provide arguments that will be applied to the template using Java String.formatted(java.lang.Object...) method.

      Provides system-level instructions to the AI model that defines its behavior and context. The system message acts as a foundational prompt that establishes the AI's role, constraints, and operational parameters. It is processed before user messages and helps maintain consistent behavior throughout the interaction.

      Parameters:
      templateId - the id of the template to use
      args - the arguments to apply to the template
    • userMessage

    • tools

      Agent.StreamEffect.Builder tools(Object tool, Object... otherTools)
      Adds one or more tool instances or classes that the AI model can use.

      Each argument can be either an object instance or a Class object. If a Class is provided, it will be instantiated at runtime using the configured DependencyProvider.

      Each instance or class must have at least one public method annotated with FunctionTool. If no such method is found, an IllegalArgumentException will be thrown. These methods will be available as tools for the AI model to invoke.

      Returns:
      this builder for method chaining
    • tools

      Agent.StreamEffect.Builder tools(List<Object> toolInstancesOrClasses)
      Adds one or more tool instances or classes that the AI model can use.

      Each element in the list can be either an object instance or a Class object. If a Class is provided, it will be instantiated at runtime using the configured DependencyProvider.

      Each instance or class must have at least one public method annotated with FunctionTool. If no such method is found, an IllegalArgumentException will be thrown. These methods will be available as tools for the AI model to invoke.

      Parameters:
      toolInstancesOrClasses - one or more objects or classes exposing tool methods
      Returns:
      this builder for method chaining
    • mcpTools

      Adds tools from one or more remote MCP servers.

      Construct instances using RemoteMcpTools.fromServer(String)

    • mcpTools

      Adds tools from one or more remote MCP servers.

      Construct instances using RemoteMcpTools.fromServer(String)

    • reply

      Agent.StreamEffect reply(String message)
      Create a message reply without calling the model.
      Parameters:
      message - The payload of the reply.
      Returns:
      A message reply.
    • reply

      Agent.StreamEffect reply(String message, Metadata metadata)
      Create a message reply without calling the model.
      Parameters:
      message - The payload of the reply.
      metadata - The metadata for the message.
      Returns:
      A message reply.
    • error

      Agent.StreamEffect error(String message)
      Create an error reply without calling the model. A short version of { streamEffects().error(new CommandException(message))}.
      Parameters:
      message - The error message.
      Returns:
      An error reply.
    • error

      Agent.StreamEffect error(CommandException commandException)
      Create an error reply. CommandException will be serialized and sent to the client. It's possible to catch it with try-catch statement.
      Parameters:
      commandException - The command exception to be returned.
      Returns:
      An error reply.
    • memory