# Beschreibe eine Funktion für ein KI-Modell mit einem JSON-Schema

> Wandle ein kompaktes Total.js-Schema mit toAITool() und toAIObject() in die Tool- oder Objektdefinition um, die ein KI-Modell erwartet, und lass eine Action ihr eigenes MCP-Tool erzeugen.

Framework: total5
Product: Total.js 5 (total5@0.0.20)
Language: de
Content-SHA256: ca335f909fc86b8a575b73ae786256036178d15c702867c7c9d4cf16ea19c74a
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: total5-installed@total5@0.0.19
Review: not-recorded

Das kompakte Schema, das du schon für `input` schreibst (`'*name:String // The name, age:Number'`), genügt, um einem KI-Modell eine Funktion zu beschreiben. `0.0.20` fügt drei Umwandlungen hinzu:

| Aufruf | Ergebnis |
|---|---|
| `'<schema>'.toJSONSchema().toAITool(name)` | Eine Funktionsdefinition in der Form der Chat-APIs: `{ type: 'function', function: { name, description, parameters } }` |
| `'<schema>'.toJSONSchema().toAIObject(name, description)` | Ein JSON-Schema-Objekt mit `name`, `description`, `properties` und `required`, um das Modell um eine strukturierte Ausgabe zu bitten |
| `Total.actions['Name'].toAITool()` | Das MCP-Tool einer Action (Name, Beschreibung, `inputSchema` und `outputSchema`) |

Der Text nach `//` in einem Feld wird zu seiner `description`, und das liest das Modell, um zu entscheiden, was dort eingetragen wird. Ein mit `*` markiertes Feld kommt in `required`. Schicke die Eingabe eines Benutzers nicht als Anweisung an ein Modell: Das Schema beschreibt nur die Form der Argumente.

```js controllers/tools.js
exports.install = function() {
	ROUTE('GET /tool/', tool);
	ROUTE('GET /object/', object);
	ROUTE('GET /action/', action);
};

const SCHEMA = '*city:String // The name of the city, unit:String // celsius or fahrenheit';

function tool($) {
	$.json(SCHEMA.toJSONSchema().toAITool('weather'));
}

function object($) {
	$.json(SCHEMA.toJSONSchema().toAIObject('weather', 'The weather of a city'));
}

function action($) {
	$.json(Total.actions['Weather/get'].toAITool());
}
```

```js definitions/weather.js
NEWACTION('Weather/get', {
	name: 'Get the weather',
	summary: 'Returns the weather of a city',
	input: '*city:String // The name of the city',
	action: function($, model) {
		$.callback({ city: model.city, temperature: 21 });
	}
});
```
