The response format of an agent's answer (design 4.26): the JSON schema its final answer must match, and the type it must read as. A model call of the agent that offers no tools carries the schema as its responseFormat (see ModelStep.fromClient), the system prompt always states it, and an answer is checked inside the model step: an invalid one is retried once, and a second ends the turn with org.llm4s.agent.graph.GraphError.OutputInvalid. Build one with OutputFormat.of; AgentBuilder.withOutput does.
An answer that matches the schema and reads as the type then goes through the format's application checks (AgentBuilder.withOutputCheck, #2920), in the order they were added: each returns the answer's problems, and any problem makes the answer invalid exactly as a schema error does, in the same retry.
The schema's root is an object ("type": "object"), or a union of objects (#2953): an anyOf whose alternatives are all object schemas, which is what SchemaOf derives for a sealed trait or an enum whose cases all have fields. A strict response format needs an object at its root, so a union is asked for inside an envelope object, {"answer": <one alternative>}, with each alternative as strict as it was written: responseFormat and the prompt section both carry the envelope's schema, the same for every provider. The envelope is only ever on the wire. It is removed when the answer is checked, before the type's reader, the application checks, the output guardrails and the thread see the answer, so the answer stored, guarded and decoded is the alternative's JSON alone. An answer that is one of the alternatives without the envelope is accepted as it is, since a model not held to the format - on a call that offers tools, or with a provider that only states it - may leave the envelope out. What is not stored still shows the model's own text, envelope included: live TextDeltas, the invalid answer echoed in the corrective request, and the partial answer of a turn cut off at the output limit. The envelope's property is answer, or - when an alternative declares a property of that name - the first of final_answer, final_answer_2, ... that none declares. Any other root is refused when the agent is built: nest that value under a property of an object schema, and read the property from the decoded answer.
Attributes
- Companion
- object
- Source
- OutputFormat.scala
- Graph
-
- Supertypes
