juglans 0.2.13

Compiler and runtime for Juglans Workflow Language
# std/ai.jg — AI Tool Definition Library
#
# Usage:
#   libs: ["std/ai.jg"]
#
#   [t1]: ai.tool { name="search", description="Search", params={"q": {"type": "string"}} }
#   [t2]: ai.tool { name="weather", description="Weather", params={"city": {"type": "string"}} }
#
#   # Inline — no to_schema() or toolbox() needed:
#   [ask]: chat(message="...", tools=ai.get_tools([t1, t2]))
#
#   # Or mix with toolbox:
#   [ask]: chat(message="...", tools=ai.get_tools([t1]) + box.output)

# Tool definition struct.
[tool]: {
  name: str
  description: str
  params: dict = {}
  required: list = []
  text: str = ""
  schema: dict = {}
}

# Convert to OpenAI function calling schema — writes to self.schema field.
[tool.to_schema(self)]: schema = {
  "type": "function",
  "function": {
    "name": self.name,
    "description": self.description,
    "parameters": {
      "type": "object",
      "properties": self.params,
      "required": default(self.required, keys(self.params))
    }
  }
}

# Group multiple tool schemas into an array for chat(tools=...).
[toolbox(tools)]: output = tools

# Convert tool instances to OpenAI schemas in one step (replaces to_schema + toolbox).
# Usage: chat(tools=ai.get_tools([t1, t2]))
[get_tools(tools)]: output = map(tools, t => {"type": "function", "function": {"name": t.name, "description": t.description, "parameters": {"type": "object", "properties": t.params, "required": default(t.required, keys(t.params))}}})