Agents 0.0.2
Edge AI Agents SDK
Loading...
Searching...
No Matches
llm_interface.h
1
10#pragma once
11
12#include <agents-cpp/types.h>
13#include <agents-cpp/tool.h>
14#include <agents-cpp/coroutine_utils.h>
15#include <functional>
16#include <memory>
17#include <optional>
18#include <vector>
19
20namespace agents {
21
25struct LLMOptions {
29 double temperature = 0.7;
33 int max_tokens = 1024;
37 double top_p = 1.0;
41 double presence_penalty = 0.0;
45 double frequency_penalty = 0.0;
49 int timeout_ms = 30000; // 30 seconds
53 std::vector<String> stop_sequences;
57 std::optional<JsonObject> response_schema;
62 std::optional<String> response_mime_type;
63};
64
69public:
73 virtual ~LLMInterface() = default;
74
79 virtual std::vector<String> getAvailableModels() = 0;
80
85 virtual void setModel(const String& model) = 0;
86
91 virtual String getModel() const = 0;
92
97 virtual void setApiKey(const String& api_key) = 0;
98
103 virtual void setApiBase(const String& api_base) = 0;
104
109 virtual void setOptions(const LLMOptions& options) = 0;
110
115 virtual LLMOptions getOptions() const = 0;
116
122 virtual LLMResponse complete(const String& prompt);
123
129 virtual LLMResponse complete(const std::vector<Message>& messages);
130
138 const std::vector<Message>& messages,
139 const std::vector<JsonObject>& tools_schema
140 );
141
147 virtual LLMResponse chat(const std::vector<Message>& messages) = 0;
148
156 const std::vector<Message>& messages,
157 const std::vector<std::shared_ptr<Tool>>& tools
158 ) = 0;
159
165 virtual void streamChat(
166 const std::vector<Message>& messages,
167 std::function<void(const String&, bool)> callback
168 ) = 0;
169
175 virtual Task<LLMResponse> completeAsync(const String& prompt);
176
182 virtual Task<LLMResponse> completeAsync(const std::vector<Message>& messages);
183
189 virtual Task<LLMResponse> chatAsync(const std::vector<Message>& messages);
190
198 const std::vector<Message>& messages,
199 const std::vector<std::shared_ptr<Tool>>& tools
200 );
201
208 const std::vector<Message>& messages
209 );
210};
211
220std::shared_ptr<LLMInterface> createLLM(
221 const String& provider,
222 const String& api_key,
223 const String& model = ""
224);
225
226} // namespace agents
A minimal AsyncGenerator implementation that doesn't rely on coroutines.
Definition coroutine_utils.h:142
Interface for language model providers (OpenAI, Anthropic, Google, Ollama)
Definition llm_interface.h:68
virtual LLMResponse chat(const std::vector< Message > &messages)=0
Generate completion from a list of messages.
virtual void setOptions(const LLMOptions &options)=0
Set options for API calls.
virtual ~LLMInterface()=default
Destructor.
virtual AsyncGenerator< String > streamChatAsync(const std::vector< Message > &messages)
Stream chat with AsyncGenerator.
virtual void setModel(const String &model)=0
Set the model to use.
virtual void setApiKey(const String &api_key)=0
Set API key.
virtual Task< LLMResponse > completeAsync(const std::vector< Message > &messages)
Async complete from a list of messages.
virtual std::vector< String > getAvailableModels()=0
Get available models from this provider.
virtual LLMOptions getOptions() const =0
Get current options.
virtual Task< LLMResponse > completeAsync(const String &prompt)
Async complete from a prompt.
virtual void setApiBase(const String &api_base)=0
Set API base URL (for self-hosted or proxied endpoints)
virtual LLMResponse complete(const std::vector< Message > &messages)
Generate completion from a list of messages.
virtual LLMResponse completeWithTools(const std::vector< Message > &messages, const std::vector< JsonObject > &tools_schema)
Generate completion with available tools.
virtual LLMResponse complete(const String &prompt)
Generate completion from a prompt.
virtual LLMResponse chatWithTools(const std::vector< Message > &messages, const std::vector< std::shared_ptr< Tool > > &tools)=0
Generate completion with available tools.
virtual void streamChat(const std::vector< Message > &messages, std::function< void(const String &, bool)> callback)=0
Stream results with callback.
virtual String getModel() const =0
Get current model.
virtual Task< LLMResponse > chatAsync(const std::vector< Message > &messages)
Async chat from a list of messages.
virtual Task< LLMResponse > chatWithToolsAsync(const std::vector< Message > &messages, const std::vector< std::shared_ptr< Tool > > &tools)
Async chat with tools.
Provide a future-based fallback for Task.
Definition coroutine_utils.h:115
Tools Namespace.
Definition file_tool.h:15
Framework Namespace.
Definition agent.h:18
std::shared_ptr< LLMInterface > createLLM(const String &provider, const String &api_key, const String &model="")
Factory function to create a specific LLM provider.
std::string String
String type.
Definition types.h:27
Options for LLM API calls.
Definition llm_interface.h:25
double presence_penalty
The presence penalty of the LLM.
Definition llm_interface.h:41
std::optional< String > response_mime_type
Response MIME type for structured output.
Definition llm_interface.h:62
double top_p
The top p of the LLM.
Definition llm_interface.h:37
double temperature
The temperature of the LLM.
Definition llm_interface.h:29
int max_tokens
The maximum number of tokens.
Definition llm_interface.h:33
std::optional< JsonObject > response_schema
Response schema for structured output (JSON schema)
Definition llm_interface.h:57
std::vector< String > stop_sequences
The stop sequences of the LLM.
Definition llm_interface.h:53
double frequency_penalty
The frequency penalty of the LLM.
Definition llm_interface.h:45
int timeout_ms
The timeout in milliseconds.
Definition llm_interface.h:49
Response from an LLM.
Definition types.h:85