Repository navigation
Conversation
## Problem kyo had no first-class way to call a language model. Using an LLM meant reaching for a mainstream SDK and writing the orchestration by hand: authoring JSON schemas, running the tool-call loop, threading the message list, parsing streaming deltas, and decoding replies. ## Solution Add kyo-ai, a module where a call to a language model is a typed value you compose, not a request you orchestrate. You declare the result type and the capabilities the model may use; the module derives the schema, runs the loop, and decodes the reply. - `AI.gen[A]` returns a typed `A`: the result schema is derived from `A derives Schema`, the model is forced to that shape, and the reply is decoded. `AI` is a first-class instance value (one conversation slot); `LLM` is a custom `ArrowEffect` whose single world-reaching op runs the eval loop. - A composable generation surface, each enabled via `AI.enable`: `Tool` (a typed function the model may call, with an async body), `Prompt` (instructions), `Thought` (typed reasoning woven into the result schema), `Mode` (generation-interception middleware). - `Agent`: an actor-backed conversational entity on kyo-actor that remembers across `ask`s. - Streaming: `ai.stream[A]` in two forms inferred from `A`, incremental text for `String` (token by token) and object by object for any other type (each complete element emitted once). - Providers: an OpenAI-compatible backend (OpenAI, DeepSeek, Gemini, Groq, Baseten, OpenRouter) and the Anthropic Messages backend, both on kyo-http, with auto-config from environment API keys. Temperature is opt-in. - A typed failure hierarchy (`AIException`), the `Config`/`Context`/`Image` value types, and cross-run misuse detection. Supporting kyo-schema change the module builds on: a `@doc` annotation for JSON Schema field descriptions, recorded on each field during derivation and surfaced in the generated schema. ## Notes - Cross-platform: JVM, Scala.js, and Scala Native. - Tested with an in-process server implementing both wire protocols, plus eight runnable `*Demo.scala` exemplars validated live against OpenAI and Anthropic.
hearnadam
reviewed
Jun 24, 2026
| // The message `content` is polymorphic on the wire: a bare string for text messages, a parts array for | ||
| // vision messages. It is carried as a Structure.Value, whose identity Schema writes shape-aware (a string | ||
| // stays a string, a sequence becomes an array), reproducing both shapes from one field with no union. | ||
| case class MessageEntry( |
Collaborator
There was a problem hiding this comment.
Can this be @CamelCase or whatever? now that we have the schema control? @DamianReeves
Collaborator
Author
There was a problem hiding this comment.
I believe we'd need #1713 and use an untagged union here.
Comment on lines
+84
to
+85
| /** A provider: its display name, base URL, the key env-var name, and the wire completion backend. */ | ||
| trait Provider( |
Collaborator
There was a problem hiding this comment.
any reason to choose a trait over an abstract class?
## Problem kyo-ai cross-built only to JVM, JS, and Native, even though all of its dependencies (kyo-core, kyo-schema, kyo-http, kyo-actor) already target Wasm. That left it the lone app module on the AI/MCP boundary without a Wasm artifact. ## Solution Add WasmPlatform and `wasm-settings` to the kyo-ai crossProject and register `kyo-ai`.wasm in the kyoWasm aggregate, mirroring kyo-jsonrpc-http (a Wasm crossProject that also depends on kyo-http). Source is shared-only, so no platform tree was added. The CONTRIBUTING platform notes now list Wasm. ## Notes Validated with `kyo-aiWasm/test`: 216 tests, all passing on Node, including the in-process TestCompletionServer binding and the OpenAI/Anthropic completion, streaming, and agent paths.
Provider carries constructor parameters and is extended only by single-inheritance case objects, so an abstract class is the idiomatic base over a parameterized trait. Addresses review feedback on #1707.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
kyo had no first-class way to call a language model. Using an LLM meant reaching for a mainstream SDK and writing the orchestration by hand: authoring JSON schemas, running the tool-call loop, threading the message list, parsing streaming deltas, and decoding replies.
Solution
Add kyo-ai, a module where a call to a language model is a typed value you compose, not a request you orchestrate. You declare the result type and the capabilities the model may use; the module derives the schema, runs the loop, and decodes the reply.
AI.gen[A]returns a typedA: the result schema is derived fromA derives Schema, the model is forced to that shape, and the reply is decoded.AIis a first-class instance value (one conversation slot);LLMis a customArrowEffectwhose single world-reaching op runs the eval loop.AI.enable:Tool(a typed function the model may call, with an async body),Prompt(instructions),Thought(typed reasoning woven into the result schema),Mode(generation-interception middleware).Agent: an actor-backed conversational entity on kyo-actor that remembers acrossasks.ai.stream[A]in two forms inferred fromA, incremental text forString(token by token) and object by object for any other type (each complete element emitted once).AIException), theConfig/Context/Imagevalue types, and cross-run misuse detection.Supporting kyo-schema change the module builds on: a
@docannotation for JSON Schema field descriptions, recorded on each field during derivation and surfaced in the generated schema.Notes
*Demo.scalaexemplars validated live against OpenAI and Anthropic.