|
NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
|
LLM provider that adapts to any API via a JSON schema. More...
#include <schema_provider.h>
Classes | |
| struct | Config |
| Configuration for schema-based provider. More... | |
Public Member Functions | |
| asio::awaitable< ChatCompletion > | complete_async (const CompletionParams ¶ms) override |
| Async completion — single wire path implemented over the owned ConnPool (HTTP keep-alive). | |
| ChatCompletion | complete_stream (const CompletionParams ¶ms, const StreamCallback &on_chunk) override |
Sync completion is inherited from Provider::complete(), which drives complete_async via neograph::async::run_sync. | |
| asio::awaitable< ChatCompletion > | complete_stream_async (const CompletionParams ¶ms, const StreamCallback &on_chunk) override |
| Async streaming completion — native override (issue #4). | |
| std::string | get_name () const override |
| Get the provider name (from the schema's "name" field). | |
| asio::awaitable< ChatCompletion > | invoke (const CompletionParams ¶ms, StreamCallback on_chunk) override |
| v1.0 single-dispatch override (Candidate 6 PR6). | |
| ~SchemaProvider () | |
| Destructor — shuts down the background HTTP loop + worker thread held alongside the ConnPool. | |
Public Member Functions inherited from neograph::Provider | |
| virtual ChatCompletion | complete (const CompletionParams ¶ms) |
| Perform a synchronous LLM completion. | |
Static Public Member Functions | |
| static std::unique_ptr< SchemaProvider > | create (const Config &config) |
| Create a schema-based provider instance. | |
Friends | |
| class | neograph::llm::test_access::SchemaProviderTestAccess |
LLM provider that adapts to any API via a JSON schema.
The schema describes connection details, request/response formats, tool call conventions, and streaming protocols for a given LLM vendor. Built-in schemas: "openai", "claude", "gemini".
Definition at line 65 of file schema_provider.h.
| neograph::llm::SchemaProvider::~SchemaProvider | ( | ) |
Destructor — shuts down the background HTTP loop + worker thread held alongside the ConnPool.
Out-of-line so the ConnPool forward declaration is enough at this header.
|
overridevirtual |
Async completion — single wire path implemented over the owned ConnPool (HTTP keep-alive).
The schema_mutex_ still serializes the body-build and response-parse phases (yyjson_mut_doc traversal is not thread-safe even for reads), but the network I/O happens off-lock so concurrent fan-out still overlaps.
Reimplemented from neograph::Provider.
|
overridevirtual |
Sync completion is inherited from Provider::complete(), which drives complete_async via neograph::async::run_sync.
Streaming completion (HTTP/SSE httplib path; WS path dispatched to complete_stream_ws_responses when use_websocket=true and the schema is openai-responses).
Locking contract for on_chunk: the callback is invoked from inside httplib's content callback (HTTP/SSE) or the WebSocket recv loop (WS), in BOTH cases with schema_mutex_ NOT held — the lock is taken only during the per-call body- build + per-call response-parse phases at the start of the request, then released before the network roundtrip begins. Parse state passed through on_chunk (accumulated full_content, tool-call map, etc.) is stack-local to this call and not shared with the schema_mutex_-protected schema templates. Callers can therefore (a) safely call other provider methods from inside on_chunk without deadlocking, and (b) assume tokens emitted by concurrent complete_stream calls on the same provider do not interleave their parse state.
Reimplemented from neograph::Provider.
|
overridevirtual |
Async streaming completion — native override (issue #4).
For the WebSocket Responses path (use_websocket=true, openai-responses schema) this co_awaits the existing complete_stream_ws_responses directly — no bridge thread, no nested run_sync, no shared-state race against the awaiter's io_context.
For the HTTP/SSE path (httplib synchronous) it defers to Provider::complete_stream_async's base implementation, which post-#4 spawns a dedicated worker thread for complete_stream and dispatches tokens back onto the awaiter's executor — so the engine's io_context worker stays responsive and the user on_chunk runs single-threaded with the awaiting coroutine.
Reimplemented from neograph::Provider.
|
static |
Create a schema-based provider instance.
If schema_path matches a built-in name, the embedded schema is used. Otherwise it is treated as a file path.
| config | Provider configuration with schema path and API key. |
| std::runtime_error | If the schema cannot be loaded or parsed. |
|
overridevirtual |
Get the provider name (from the schema's "name" field).
Implements neograph::Provider.
|
overridevirtual |
v1.0 single-dispatch override (Candidate 6 PR6).
Anchors the dispatch surface — engine provider->invoke(...) calls land here directly instead of bouncing through the base default that re-forwards to the 4-virtual chain. v0.9 body routes through existing native overrides (no behavioural change); v1.0 will fold complete_async + complete_stream_async bodies into invoke() and delete the legacy methods.
Reimplemented from neograph::Provider.