Class CohereToolConverter

java.lang.Object
com.tnsai.llm.providers.CohereToolConverter

public final class CohereToolConverter extends Object
Translates the OpenAI-flavoured intermediate tool schema into Cohere's chat-API tool shape.

Cohere's tool definition is structurally different from OpenAI's:

 {
   "name": "search",
   "description": "Searches a database",
   "parameter_definitions": {
     "query": { "description": "...", "type": "str", "required": true }
   }
 }
 

Two shape differences from OpenAI:

  • Parameters are flat (parameter_definitions: {name → spec}) rather than nested under a JSON-Schema parameters.properties.
  • required lives on each individual parameter spec, not in a separate required: [...] array.

Cohere has no native examples surface, so @ToolExample positives + negatives both fold into description via ToolExampleConverter.foldAllExamplesIntoDescription(java.lang.String, java.util.List<java.util.Map<java.lang.String, java.lang.Object>>).

Type names are translated from JSON-Schema to Cohere's Python-style aliases (string → str, integer → int, etc.) — Cohere's API documents type names rather than parsing arbitrary JSON-Schema.

See Also:
  • Method Details

    • convertToCohereTools

      public static List<Map<String,Object>> convertToCohereTools(List<Map<String,Object>> tools)
      Convert an OpenAI-flavoured tool list into Cohere's tool list.

      Tools whose type is not "function", or whose function object is missing, are skipped silently — the intermediate schema only emits function-typed entries today.

      Parameters:
      tools - intermediate tools (OpenAI shape); may be null
      Returns:
      Cohere-shaped tools; empty list if the input is empty