CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
LLMConnection.h File Reference

Named, node-owned connection to an LLM endpoint (CMSDK 2.2.0). More...

#include "Utils.h"
#include "xml_parser.h"
#include <string>
#include <vector>
Include dependency graph for LLMConnection.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  cmlabs::LLMHeader
 One configured HTTP header. More...
struct  cmlabs::LLMConstraints
 Per-connection constraints declared on the <llm> element. More...
struct  cmlabs::LLMStats
 Connection statistics: uptime, bytes, requests, tokens and cost. More...
class  cmlabs::LLMConnection
 Named, node-owned connection to an LLM endpoint. More...

Namespaces

namespace  cmlabs

Typedefs

typedef bool(* cmlabs::LLMStreamCallback) (const char *token, uint32 size, void *userData)
 Sink for incremental streaming output (mode B).
typedef void(* cmlabs::LLMOwnerEndCallback) (void *owner, LLMConnection *connection, const LLMStats &finalStats)
 Owner-notification hook, fired when a connection ends.

Enumerations

enum  cmlabs::LLMResult {
  cmlabs::LLM_OK = 0 , cmlabs::LLM_ERR_NOT_CONFIGURED , cmlabs::LLM_ERR_NOT_CONNECTED , cmlabs::LLM_ERR_NOT_IMPLEMENTED ,
  cmlabs::LLM_ERR_CONFIG_EMPTY , cmlabs::LLM_ERR_CONFIG_NOT_LLM , cmlabs::LLM_ERR_CONFIG_PARSE , cmlabs::LLM_ERR_CONFIG_NO_NAME ,
  cmlabs::LLM_ERR_CONFIG_NO_VENDOR , cmlabs::LLM_ERR_CONFIG_UNKNOWN_VENDOR , cmlabs::LLM_ERR_CONFIG_NO_ENDPOINT , cmlabs::LLM_ERR_CONFIG_INLINE_SECRET ,
  cmlabs::LLM_ERR_CONFIG_INVALID , cmlabs::LLM_ERR_UNKNOWN_MODEL , cmlabs::LLM_ERR_SECRET_UNRESOLVED , cmlabs::LLM_ERR_NO_INPUT ,
  cmlabs::LLM_ERR_HTTP_UNREACHABLE , cmlabs::LLM_ERR_HTTP , cmlabs::LLM_ERR_REPLY_PARSE , cmlabs::LLM_ERR_CONFIG_BAD_TRANSPORT ,
  cmlabs::LLM_ERR_STREAM_CANCELLED
}
 Typed result codes returned by every LLMConnection operation. More...
enum  cmlabs::LLMVendorType {
  cmlabs::LLM_VENDOR_NONE = 0 , cmlabs::LLM_VENDOR_OPENAI , cmlabs::LLM_VENDOR_ANTHROPIC , cmlabs::LLM_VENDOR_BEDROCK ,
  cmlabs::LLM_VENDOR_GOOGLE , cmlabs::LLM_VENDOR_CUSTOM
}
 Vendor family recognised from <llmvendor type="...">. More...
enum  cmlabs::LLMStreamTransport { cmlabs::LLM_STREAM_NONE = 0 , cmlabs::LLM_STREAM_SSE , cmlabs::LLM_STREAM_EVENTSTREAM , cmlabs::LLM_STREAM_CHUNKED }
 Streaming wire format used by mode B. More...

Functions

const char * cmlabs::LLMResultText (LLMResult result)
 Human-readable name for an ::LLMResult, for logs and error reporting.
const char * cmlabs::LLMVendorTypeText (LLMVendorType type)
 Human-readable name for an ::LLMVendorType.
const char * cmlabs::LLMStreamTransportText (LLMStreamTransport transport)
 Human-readable name for an ::LLMStreamTransport.

Detailed Description

Named, node-owned connection to an LLM endpoint (CMSDK 2.2.0).

An LLMConnection turns talking to a language model into declared, observable system configuration instead of ad-hoc HTTP scattered through modules. The endpoint, vendor shape, model list, credential reference and per-connection constraints all live in XML; code calls configure(), connect() and then interact() or interactStream().

Configured from the reserved <llm> named-connection element, which contains one <llmvendor> vendor-descriptor sub-block carrying <header>, <requesttemplate>, <responsetemplate> and <models>.

Warning
Secrets are NEVER inline in the XML. The apikeyref attribute is an indirect reference resolved at configure() time: env:NAME reads environment variable NAME; file:/path reads the file contents (trailing whitespace trimmed); a bare NAME is the legacy form (env var, else a key=value entry in the optional secretsfile). An inline apikey attribute or <apikey> child is a typed configuration error (::LLM_ERR_CONFIG_INLINE_SECRET). The secret value, and the detail of any failure to resolve it, never appears in logs, errors or status output.

Two call modes are supported: mode A is a blocking request/reply exchange (interact()); mode B streams incremental tokens to a callback (interactStream()) over SSE, AWS event-stream or raw chunked transfer, chosen once at configure() time so callers never branch on vendor.

Note
There is no SWIG/Python exposure for this class: it is C++ only.
Constraint fields are parsed and stored but NOT enforced (see ::LLMConstraints).

Definition in file LLMConnection.h.