CoreAI.Core owns the portable routing and policy model. Unity, servers, and other hosts adapt these contracts to concrete clients. Doc index: README.md.
LocalModel— local model adapter, such as LLMUnity or a future non-Unity local runtime.ClientOwnedApi— direct OpenAI-compatible API with a key owned by the user or application developer.ClientLimited— client path with local or server-enforced request/prompt limits.ServerManagedApi— production backend/proxy owns provider keys, subscriptions, quotas, model allowlists, usage, and audit.Offline/Stub— deterministic fallback for tests and demos.
LlmRouteProfiledescribes a profile id, execution mode, model alias, context window, response cap, and capabilities.LlmRouteRulemaps role patterns to profile ids. Exact role ids, prefix patterns ending with*, and*wildcard are supported.LlmRouteTablestores profiles and rules and validates duplicate/missing profile references.ILlmRouteResolverresolves an agent role to a route profile.ILlmClientRegistryis the portable role-to-client registry contract used by host adapters.LlmProviderErrormaps stable backend codes such asquota_exceeded,subscription_required,model_not_allowed, andrate_limitedtoLlmErrorCode.LlmUsageRecordandILlmUsageSinkprovide portable usage accounting contracts. Free CoreAI does not register a default sink — use a custom adapter or rely on the backend to record usage. CoreAiPro ships a backendBackendUsageSinkadapter.ILlmEntitlementPolicyandLlmEntitlementDecisionprovide portable subscription/quota/allowlist contracts. Free CoreAI does not run a client-side entitlement decorator — the backend (ServerManagedApi) is the source of truth and surfaces decisions throughLlmErrorCode.QuotaExceeded/RateLimited/ etc. CoreAiPro ships a backendBackendEntitlementPolicyadapter that callsGET /entitlements.ILlmAuthContextProviderexposes auth/session context for server-managed routes. Register viaLlmAuthContextRegistry.SetProvider(...);MeaiOpenAiChatClientreads it on every request and emitsX-Tenant-Id/X-User-Id/X-Session-Idheaders.LlmRequestContext(AsyncLocal) carries the per-request idempotency key, role id, and trace id.MeaiLlmClientpopulates a frame on everyCompleteAsync/CompleteStreamingAsync; HTTP transports emitIdempotency-Key,X-Request-Id,X-Coreai-Role. The same key is reused across decorator retries (e.g.RefreshOnUnauthorizedDecorator) so the backend can deduplicate without double-billing.IRequestHeaderProvider(onIOpenAiHttpSettings.HeaderProvider) exposes a per-settings hook for additional static headers (defaults tonullon built-in adapters).
Lesson and practice orchestrators can keep routing portable while adding per-turn policy:
AgentMemoryPolicy.SetRuntimeContextProvider(roleId, provider)injects role-specific runtime context before each request. Per-role context is appended before globalIAiPromptContextProvidersections.AiTaskRequest.AllowedToolNamesnarrows the role's tools for the current lesson slot:null= offer all registered tools; empty array = offer no tools; non-empty = allowlist only.AiTaskRequest.ForcedToolMode = Nonesends no tools for theory/chat-only turns.ScriptedLlmClient,ILlmToolCallHistory,LlmToolResultEnvelope, andIAgentTurnTraceSinksupport deterministic orchestration tests without network/model dependencies.
CoreAI.Core does not create HTTP clients, read Unity assets, or know about VContainer. CoreAiUnity converts LlmRoutingManifest into LlmRouteTable, then uses the portable resolver while still building Unity-specific clients such as LLMUnity, OpenAI-compatible HTTP, client-limited decorators, and server-managed proxy clients.
Production games such as RedoSchool should put provider keys and quota enforcement behind ServerManagedApi. The Unity client sends a user/session token to the backend; the backend performs entitlement, calls the provider, records usage, and returns stable provider errors.
- Orchestrator / chat window:
ICoreAISettings.LlmRequestTimeoutSecondsis enforced byCoreAiChatService(CancelAfterSlim, WebGL-safe) for both streaming and non-streaming chat calls. - HTTP per request:
IOpenAiHttpSettings.RequestTimeoutSecondscaps a singleMeaiOpenAiChatClientround-trip. On Unity,CoreAISettingsAsset.EffectiveHttpRequestTimeoutSecondsappliesmin(RequestTimeoutSeconds, ceil(LlmRequestTimeoutSeconds))so the transport does not outlive the orchestrator cancel window (seeMEAI_TOKENS_FACT_VS_ESTIMATE.md, §3). - Typed timeout vs cancel: When only the library timeout fires, callers may receive
LlmOperationTimeoutException.RoutingLlmClientpublishesLlmRequestCompletedwithLlmErrorCode.TimeoutvsCancelledfor non-streaming failures; streaming may still surface a terminalLlmStreamChunkwithError = "cancelled"when lower layers normalize cancellation (seeMEAI_TOKENS_FACT_VS_ESTIMATE.md, §4). - Usage accounting:
LlmUsageRecord/ILlmUsageSinkandLlmUsageReported(MessagePipe) complement routing; token counts from HTTP usage are described inMEAI_TOKENS_FACT_VS_ESTIMATE.md.