AS AgentScopeAPI 手册 / API Reference

OllamaMultiAgentFormatter

public class OllamaMultiAgentFormatter extends AbstractBaseFormatter<OllamaMessage, OllamaResponse, OllamaRequest>
源码Source io/agentscope/extensions/model/ollama/formatter/OllamaMultiAgentFormatter.java:50–508

Ollama Multi 智能体格式化器,与模型服务通信并返回生成或向量化结果。位于 io.agentscope.extensions.model.ollama.formatter 包,继承自 AbstractBaseFormatter<OllamaMessage, OllamaResponse, OllamaRequest>。核心成员包括 doFormat、parseResponse、applyOptions、applyTools、applyToolChoice、buildRequest。

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 Summary

构造器Constructor说明Description
public OllamaMultiAgentFormatter()
创建OllamaMultiAgentFormatter 使用默认会话历史提示词。
Create a OllamaMultiAgentFormatter with default conversation history prompt.
public OllamaMultiAgentFormatter(String conversationHistoryPrompt)
创建OllamaMultiAgentFormatter 使用自定义会话历史提示词。
Create a OllamaMultiAgentFormatter with custom conversation history prompt.
public OllamaMultiAgentFormatter(boolean promoteToolResultImages)
初始化 `OllamaMultiAgentFormatter` 实例。
Creates a new instance.
public OllamaMultiAgentFormatter(String conversationHistoryPrompt, boolean promoteToolResultImages)
初始化 `OllamaMultiAgentFormatter` 实例。
Creates a new instance.

方法摘要Method Summary

方法Method说明Description
protected List<OllamaMessage> doFormat(List<Msg> msgs)
执行格式操作。
Performs the do format operation.
public ChatResponse parseResponse(OllamaResponse result, Instant startTime)
解析响应。
Parses the response.
public void applyOptions(OllamaRequest request, GenerateOptions options, GenerateOptions defaultOptions)
应用选项。
Performs the apply options operation.
public void applyOptions(OllamaRequest request, OllamaOptions options, OllamaOptions defaultOptions)
应用选项。
Apply OllamaOptions to the request.
public void applyTools(OllamaRequest request, List<ToolSchema> tools)
应用工具。
Performs the apply tools operation.
public void applyToolChoice(OllamaRequest request, ToolChoice toolChoice)
应用工具选项。
Performs the apply tool choice operation.
public OllamaRequest buildRequest(String model, List<OllamaMessage> messages, boolean stream, OllamaOptions options, OllamaOptions defaultOptions, List<ToolSchema> tools, ToolChoice toolChoice)
构建请求。
Build a complete OllamaRequest for the API call.
public String convertToolResultToString(List<ContentBlock> blocks)
转换 `convertToolResultToString`。
Convert list of content blocks (usually from tool result) to string.

构造器详情Constructor Detail

OllamaMultiAgentFormatter

public OllamaMultiAgentFormatter()

创建OllamaMultiAgentFormatter 使用默认会话历史提示词。

Create a OllamaMultiAgentFormatter with default conversation history prompt.

源码Source io/agentscope/extensions/model/ollama/formatter/OllamaMultiAgentFormatter.java:69–71

OllamaMultiAgentFormatter

public OllamaMultiAgentFormatter(String conversationHistoryPrompt)

创建OllamaMultiAgentFormatter 使用自定义会话历史提示词。

Create a OllamaMultiAgentFormatter with custom conversation history prompt.

参数Parameters
名称Name类型Type说明Description
conversationHistoryPromptString会话历史提示词(类型 `String`)。The prompt to prepend before conversation history
源码Source io/agentscope/extensions/model/ollama/formatter/OllamaMultiAgentFormatter.java:78–80

OllamaMultiAgentFormatter

public OllamaMultiAgentFormatter(boolean promoteToolResultImages)

初始化 OllamaMultiAgentFormatter 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
promoteToolResultImagesbooleanpromote 工具结果 Images(类型 `boolean`)。The promote tool result images.
源码Source io/agentscope/extensions/model/ollama/formatter/OllamaMultiAgentFormatter.java:82–84

OllamaMultiAgentFormatter

public OllamaMultiAgentFormatter(String conversationHistoryPrompt, boolean promoteToolResultImages)

初始化 OllamaMultiAgentFormatter 实例。

Creates a new instance.

参数Parameters
名称Name类型Type说明Description
conversationHistoryPromptString会话历史提示词(类型 `String`)。The conversation history prompt.
promoteToolResultImagesbooleanpromote 工具结果 Images(类型 `boolean`)。The promote tool result images.
源码Source io/agentscope/extensions/model/ollama/formatter/OllamaMultiAgentFormatter.java:86–94

方法详情Method Detail

doFormat

protected List<OllamaMessage> doFormat(List<Msg> msgs)

执行格式操作。

Performs the do format operation.

参数Parameters
名称Name类型Type说明Description
msgsList<Msg>消息列表(类型 `List`)。The msgs.
返回Returns List<OllamaMessage>
返回列出。Returns list.
源码Source io/agentscope/extensions/model/ollama/formatter/OllamaMultiAgentFormatter.java:96–159

parseResponse

public ChatResponse parseResponse(OllamaResponse result, Instant startTime)

解析响应。

Parses the response.

参数Parameters
名称Name类型Type说明Description
resultOllamaResponse结果(类型 `OllamaResponse`)。The result.
startTimeInstant启动时间(类型 `Instant`)。The start time.
返回Returns ChatResponse
返回ChatResponse。Returns chat response.
源码Source io/agentscope/extensions/model/ollama/formatter/OllamaMultiAgentFormatter.java:244–247

applyOptions

public void applyOptions(OllamaRequest request, GenerateOptions options, GenerateOptions defaultOptions)

应用选项。

Performs the apply options operation.

参数Parameters
名称Name类型Type说明Description
requestOllamaRequest请求(类型 `OllamaRequest`)。The request.
optionsGenerateOptions选项(类型 `GenerateOptions`)。The options.
defaultOptionsGenerateOptions默认选项(类型 `GenerateOptions`)。The default options.
源码Source io/agentscope/extensions/model/ollama/formatter/OllamaMultiAgentFormatter.java:249–253

applyOptions

public void applyOptions(OllamaRequest request, OllamaOptions options, OllamaOptions defaultOptions)

应用选项。

Apply OllamaOptions to the request.

参数Parameters
名称Name类型Type说明Description
requestOllamaRequest请求(类型 `OllamaRequest`)。The request to apply options to
optionsOllamaOptions运行时选项。The runtime options
defaultOptionsOllamaOptions默认选项。The default options
源码Source io/agentscope/extensions/model/ollama/formatter/OllamaMultiAgentFormatter.java:262–265

applyTools

public void applyTools(OllamaRequest request, List<ToolSchema> tools)

应用工具。

Performs the apply tools operation.

参数Parameters
名称Name类型Type说明Description
requestOllamaRequest请求(类型 `OllamaRequest`)。The request.
toolsList<ToolSchema>工具列表(类型 `List`)。The tools.
源码Source io/agentscope/extensions/model/ollama/formatter/OllamaMultiAgentFormatter.java:267–270

applyToolChoice

public void applyToolChoice(OllamaRequest request, ToolChoice toolChoice)

应用工具选项。

Performs the apply tool choice operation.

参数Parameters
名称Name类型Type说明Description
requestOllamaRequest请求(类型 `OllamaRequest`)。The request.
toolChoiceToolChoice工具选项(类型 `ToolChoice`)。The tool choice.
源码Source io/agentscope/extensions/model/ollama/formatter/OllamaMultiAgentFormatter.java:272–275

buildRequest

public OllamaRequest buildRequest(String model, List<OllamaMessage> messages, boolean stream, OllamaOptions options, OllamaOptions defaultOptions, List<ToolSchema> tools, ToolChoice toolChoice)

构建请求。

Build a complete OllamaRequest for the API call.

参数Parameters
名称Name类型Type说明Description
modelString模型实例(类型 `String`)。Model name
messagesList<OllamaMessage>消息列表(类型 `List`)。Formatted Ollama messages
streamboolean判断是否到启用流式。Whether to enable streaming
optionsOllamaOptions选项(类型 `OllamaOptions`)。Generation options
defaultOptionsOllamaOptions默认选项(类型 `OllamaOptions`)。Default generation options
toolsList<ToolSchema>工具列表(类型 `List`)。Tool schemas
toolChoiceToolChoice工具选项(类型 `ToolChoice`)。Tool choice configuration
返回Returns OllamaRequest
返回OllamaRequest。Complete OllamaRequest ready for API call
源码Source io/agentscope/extensions/model/ollama/formatter/OllamaMultiAgentFormatter.java:289–315

convertToolResultToString

public String convertToolResultToString(List<ContentBlock> blocks)

转换 convertToolResultToString。

Convert list of content blocks (usually from tool result) to string.

参数Parameters
名称Name类型Type说明Description
blocksList<ContentBlock>内容块列表(类型 `List`)。The list of content blocks to convert
返回Returns String
返回字符串结果。The string representation of the content blocks
源码Source io/agentscope/extensions/model/ollama/formatter/OllamaMultiAgentFormatter.java:460–476
基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.