Update.
This commit is contained in:
Executable
+38
@@ -0,0 +1,38 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
#ifndef R_AGENT_H
|
||||
#define R_AGENT_H
|
||||
|
||||
#include "messages.h"
|
||||
#include "r_error.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#define AGENT_MAX_ITERATIONS 300
|
||||
#define AGENT_MAX_TOOL_RETRIES 3
|
||||
|
||||
typedef enum {
|
||||
AGENT_STATE_IDLE,
|
||||
AGENT_STATE_RUNNING,
|
||||
AGENT_STATE_EXECUTING_TOOLS,
|
||||
AGENT_STATE_COMPLETED,
|
||||
AGENT_STATE_MAX_ITERATIONS,
|
||||
AGENT_STATE_ERROR
|
||||
} agent_state_t;
|
||||
|
||||
typedef struct agent_t *agent_handle;
|
||||
|
||||
agent_handle agent_create(const char *goal, messages_handle messages);
|
||||
void agent_destroy(agent_handle agent);
|
||||
|
||||
void agent_set_max_iterations(agent_handle agent, int max);
|
||||
void agent_set_verbose(agent_handle agent, bool verbose);
|
||||
|
||||
agent_state_t agent_get_state(agent_handle agent);
|
||||
const char *agent_get_error(agent_handle agent);
|
||||
int agent_get_iteration_count(agent_handle agent);
|
||||
|
||||
char *agent_run(agent_handle agent, const char *user_message);
|
||||
char *agent_chat(const char *user_message, messages_handle messages);
|
||||
char *agent_chat_with_limit(const char *user_message, int max_iterations, messages_handle messages);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,9 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
#ifndef R_BASH_EXECUTOR_H
|
||||
#define R_BASH_EXECUTOR_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
char *r_bash_execute(const char *command, bool interactive);
|
||||
|
||||
#endif
|
||||
Executable
+24
@@ -0,0 +1,24 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
#ifndef R_DB_H
|
||||
#define R_DB_H
|
||||
|
||||
#include "r_error.h"
|
||||
#include <json-c/json.h>
|
||||
|
||||
typedef struct db_t *db_handle;
|
||||
|
||||
db_handle db_open(const char *path);
|
||||
void db_close(db_handle db);
|
||||
|
||||
r_status_t db_init(db_handle db);
|
||||
r_status_t db_kv_set(db_handle db, const char *key, const char *value);
|
||||
r_status_t db_kv_get(db_handle db, const char *key, char **value);
|
||||
r_status_t db_execute(db_handle db, const char *sql, struct json_object **result);
|
||||
|
||||
char *db_get_schema(db_handle db);
|
||||
r_status_t db_store_file_version(db_handle db, const char *path);
|
||||
r_status_t db_save_conversation(db_handle db, const char *session_key, const char *data);
|
||||
r_status_t db_load_conversation(db_handle db, const char *session_key, char **data);
|
||||
|
||||
#endif
|
||||
Executable
+26
@@ -0,0 +1,26 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
#ifndef R_HTTP_CLIENT_H
|
||||
#define R_HTTP_CLIENT_H
|
||||
|
||||
#include "r_error.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct http_client_t *http_client_handle;
|
||||
|
||||
http_client_handle http_client_create(const char *bearer_token);
|
||||
void http_client_destroy(http_client_handle client);
|
||||
|
||||
void http_client_set_show_spinner(http_client_handle client, bool show);
|
||||
void http_client_set_timeout(http_client_handle client, long timeout_seconds);
|
||||
void http_client_set_connect_timeout(http_client_handle client, long timeout_seconds);
|
||||
|
||||
r_status_t http_post(http_client_handle client, const char *url,
|
||||
const char *data, char **response);
|
||||
r_status_t http_get(http_client_handle client, const char *url, char **response);
|
||||
|
||||
r_status_t http_post_simple(const char *url, const char *bearer_token,
|
||||
const char *data, char **response);
|
||||
r_status_t http_get_simple(const char *url, const char *bearer_token, char **response);
|
||||
|
||||
#endif
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
#ifndef R_MESSAGES_H
|
||||
#define R_MESSAGES_H
|
||||
|
||||
#include "r_error.h"
|
||||
#include <json-c/json.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct messages_t *messages_handle;
|
||||
|
||||
messages_handle messages_create(const char *session_id);
|
||||
void messages_destroy(messages_handle msgs);
|
||||
|
||||
r_status_t messages_set_session_id(messages_handle msgs, const char *session_id);
|
||||
const char *messages_get_session_id(messages_handle msgs);
|
||||
|
||||
r_status_t messages_add(messages_handle msgs, const char *role, const char *content);
|
||||
r_status_t messages_add_object(messages_handle msgs, struct json_object *message);
|
||||
r_status_t messages_add_tool_call(messages_handle msgs, struct json_object *message);
|
||||
r_status_t messages_add_tool_result(messages_handle msgs, const char *tool_call_id, const char *result);
|
||||
|
||||
r_status_t messages_remove_last(messages_handle msgs);
|
||||
r_status_t messages_clear(messages_handle msgs);
|
||||
|
||||
r_status_t messages_save(messages_handle msgs);
|
||||
r_status_t messages_load(messages_handle msgs);
|
||||
|
||||
struct json_object *messages_to_json(messages_handle msgs);
|
||||
char *messages_to_string(messages_handle msgs);
|
||||
int messages_count(messages_handle msgs);
|
||||
|
||||
#endif
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
#ifndef R_CONFIG_H
|
||||
#define R_CONFIG_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef struct r_config_t *r_config_handle;
|
||||
|
||||
r_config_handle r_config_get_instance(void);
|
||||
void r_config_destroy(void);
|
||||
|
||||
const char *r_config_get_api_url(r_config_handle cfg);
|
||||
const char *r_config_get_models_url(r_config_handle cfg);
|
||||
const char *r_config_get_model(r_config_handle cfg);
|
||||
void r_config_set_model(r_config_handle cfg, const char *model);
|
||||
|
||||
const char *r_config_get_api_key(r_config_handle cfg);
|
||||
const char *r_config_get_db_path(r_config_handle cfg);
|
||||
|
||||
bool r_config_use_tools(r_config_handle cfg);
|
||||
bool r_config_use_strict(r_config_handle cfg);
|
||||
bool r_config_is_verbose(r_config_handle cfg);
|
||||
void r_config_set_verbose(r_config_handle cfg, bool verbose);
|
||||
|
||||
double r_config_get_temperature(r_config_handle cfg);
|
||||
|
||||
const char *r_config_get_session_id(r_config_handle cfg);
|
||||
bool r_config_set_session_id(r_config_handle cfg, const char *session_id);
|
||||
|
||||
const char *r_config_get_system_message(r_config_handle cfg);
|
||||
|
||||
#endif
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
#ifndef R_ERROR_H
|
||||
#define R_ERROR_H
|
||||
|
||||
typedef enum {
|
||||
R_SUCCESS = 0,
|
||||
R_ERROR_INVALID_ARG,
|
||||
R_ERROR_OUT_OF_MEMORY,
|
||||
R_ERROR_NOT_FOUND,
|
||||
R_ERROR_PARSE,
|
||||
R_ERROR_DB_CONNECTION,
|
||||
R_ERROR_DB_QUERY,
|
||||
R_ERROR_DB_NOT_FOUND,
|
||||
R_ERROR_HTTP_CONNECTION,
|
||||
R_ERROR_HTTP_TIMEOUT,
|
||||
R_ERROR_HTTP_RESPONSE,
|
||||
R_ERROR_JSON_PARSE,
|
||||
R_ERROR_FILE_NOT_FOUND,
|
||||
R_ERROR_FILE_READ,
|
||||
R_ERROR_FILE_WRITE,
|
||||
R_ERROR_TOOL_NOT_FOUND,
|
||||
R_ERROR_TOOL_EXECUTION,
|
||||
R_ERROR_API_KEY_MISSING,
|
||||
R_ERROR_API_ERROR,
|
||||
R_ERROR_MAX_ITERATIONS,
|
||||
R_ERROR_SESSION_INVALID,
|
||||
R_ERROR_UNKNOWN
|
||||
} r_status_t;
|
||||
|
||||
const char *r_status_string(r_status_t status);
|
||||
|
||||
#define R_CHECK(expr) do { r_status_t _s = (expr); if (_s != R_SUCCESS) return _s; } while(0)
|
||||
|
||||
#define R_CHECK_NULL(ptr) do { if (!(ptr)) return R_ERROR_INVALID_ARG; } while(0)
|
||||
|
||||
#define R_CHECK_ALLOC(ptr) do { if (!(ptr)) return R_ERROR_OUT_OF_MEMORY; } while(0)
|
||||
|
||||
#endif
|
||||
Executable
+42
@@ -0,0 +1,42 @@
|
||||
// retoor <retoor@molodetz.nl>
|
||||
|
||||
#ifndef R_TOOL_H
|
||||
#define R_TOOL_H
|
||||
|
||||
#include "r_error.h"
|
||||
#include <json-c/json.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
typedef struct tool_t tool_t;
|
||||
|
||||
typedef struct {
|
||||
struct json_object *(*get_description)(void);
|
||||
char *(*execute)(tool_t *self, struct json_object *args);
|
||||
void (*print_action)(const char *name, struct json_object *args);
|
||||
} tool_vtable_t;
|
||||
|
||||
struct tool_t {
|
||||
const tool_vtable_t *vtable;
|
||||
const char *name;
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
tool_t **tools;
|
||||
size_t count;
|
||||
size_t capacity;
|
||||
} tool_registry_t;
|
||||
|
||||
tool_registry_t *tool_registry_create(void);
|
||||
void tool_registry_destroy(tool_registry_t *registry);
|
||||
r_status_t tool_registry_register(tool_registry_t *registry, tool_t *tool);
|
||||
tool_t *tool_registry_find(tool_registry_t *registry, const char *name);
|
||||
struct json_object *tool_registry_get_descriptions(tool_registry_t *registry);
|
||||
struct json_object *tool_registry_execute(tool_registry_t *registry,
|
||||
struct json_object *tool_calls,
|
||||
bool verbose);
|
||||
|
||||
tool_registry_t *tools_get_registry(void);
|
||||
void tools_registry_shutdown(void);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user