Build a tool definition from a submodule function spec.
(spec: SubmoduleFunctionSpec)
| 124 | |
| 125 | |
| 126 | def build_submodule_tool(spec: SubmoduleFunctionSpec) -> Dict[str, Any]: |
| 127 | """Build a tool definition from a submodule function spec.""" |
| 128 | properties = {} |
| 129 | required = [] |
| 130 | for p in spec.model_params: |
| 131 | if not p.name: |
| 132 | raise ValueError( |
| 133 | f"Submodule {spec.module_path} has a parameter without a name" |
| 134 | ) |
| 135 | if p.schema and isinstance(p.schema, dict): |
| 136 | properties[p.name] = p.schema |
| 137 | else: |
| 138 | properties[p.name] = { |
| 139 | "type": p.param_type or "string", |
| 140 | "description": p.description or "", |
| 141 | } |
| 142 | if p.required: |
| 143 | required.append(p.name) |
| 144 | |
| 145 | return { |
| 146 | "type": "function", |
| 147 | "function": { |
| 148 | "name": spec.name, |
| 149 | "description": spec.description or "", |
| 150 | "parameters": { |
| 151 | "type": "object", |
| 152 | "properties": properties, |
| 153 | "required": required, |
| 154 | }, |
| 155 | }, |
| 156 | } |
| 157 | |
| 158 | |
| 159 | def load_submodule_tools_for_yaml( |
no outgoing calls