Class OllamaMultiAgentFormatter

java.lang.Object
io.agentscope.core.formatter.AbstractBaseFormatter<OllamaMessage,OllamaResponse,OllamaRequest>
io.agentscope.extensions.model.ollama.formatter.OllamaMultiAgentFormatter
All Implemented Interfaces:
io.agentscope.core.formatter.Formatter<OllamaMessage,OllamaResponse,OllamaRequest>

public class OllamaMultiAgentFormatter extends io.agentscope.core.formatter.AbstractBaseFormatter<OllamaMessage,OllamaResponse,OllamaRequest>
Ollama formatter for multi-agent conversations. Converts AgentScope Msg objects to Ollama DTO Message objects with multi-agent support. Collapses multi-agent conversation into a single user message with history tags.
  • Constructor Details

    • OllamaMultiAgentFormatter

      public OllamaMultiAgentFormatter()
      Create a OllamaMultiAgentFormatter with default conversation history prompt.
    • OllamaMultiAgentFormatter

      public OllamaMultiAgentFormatter(String conversationHistoryPrompt)
      Create a OllamaMultiAgentFormatter with custom conversation history prompt.
      Parameters:
      conversationHistoryPrompt - The prompt to prepend before conversation history
    • OllamaMultiAgentFormatter

      public OllamaMultiAgentFormatter(boolean promoteToolResultImages)
    • OllamaMultiAgentFormatter

      public OllamaMultiAgentFormatter(String conversationHistoryPrompt, boolean promoteToolResultImages)
  • Method Details

    • doFormat

      protected List<OllamaMessage> doFormat(List<io.agentscope.core.message.Msg> msgs)
      Specified by:
      doFormat in class io.agentscope.core.formatter.AbstractBaseFormatter<OllamaMessage,OllamaResponse,OllamaRequest>
    • parseResponse

      public io.agentscope.core.model.ChatResponse parseResponse(OllamaResponse result, Instant startTime)
    • applyOptions

      public void applyOptions(OllamaRequest request, io.agentscope.core.model.GenerateOptions options, io.agentscope.core.model.GenerateOptions defaultOptions)
    • applyOptions

      public void applyOptions(OllamaRequest request, OllamaOptions options, OllamaOptions defaultOptions)
      Apply OllamaOptions to the request.
      Parameters:
      request - The request to apply options to
      options - The runtime options
      defaultOptions - The default options
    • applyTools

      public void applyTools(OllamaRequest request, List<io.agentscope.core.model.ToolSchema> tools)
    • applyToolChoice

      public void applyToolChoice(OllamaRequest request, io.agentscope.core.model.ToolChoice toolChoice)
    • buildRequest

      public OllamaRequest buildRequest(String model, List<OllamaMessage> messages, boolean stream, OllamaOptions options, OllamaOptions defaultOptions, List<io.agentscope.core.model.ToolSchema> tools, io.agentscope.core.model.ToolChoice toolChoice)
      Build a complete OllamaRequest for the API call.
      Parameters:
      model - Model name
      messages - Formatted Ollama messages
      stream - Whether to enable streaming
      options - Generation options
      defaultOptions - Default generation options
      tools - Tool schemas
      toolChoice - Tool choice configuration
      Returns:
      Complete OllamaRequest ready for API call
    • convertToolResultToString

      public String convertToolResultToString(List<io.agentscope.core.message.ContentBlock> blocks)
      Convert list of content blocks (usually from tool result) to string.
      Overrides:
      convertToolResultToString in class io.agentscope.core.formatter.AbstractBaseFormatter<OllamaMessage,OllamaResponse,OllamaRequest>
      Parameters:
      blocks - The list of content blocks to convert
      Returns:
      The string representation of the content blocks