NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
types.h File Reference

Foundation types for NeoGraph: messages, tool calls, and LLM completions. More...

#include <string>
#include <vector>
#include <neograph/json.h>
Include dependency graph for types.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  neograph::ChatCompletion
 LLM completion response including the message and token usage. More...
 
struct  neograph::ChatMessage
 A message in the conversation history. More...
 
struct  neograph::ChatTool
 Tool definition metadata sent to the LLM. More...
 
struct  neograph::ToolCall
 Represents a single tool invocation requested by the LLM. More...
 
struct  neograph::ChatCompletion::Usage
 Token usage statistics for the completion. More...
 

Functions

void neograph::from_json (const json &j, ChatMessage &msg)
 Deserialize a ChatMessage from JSON.
 
void neograph::from_json (const json &j, ToolCall &tc)
 Deserialize a ToolCall from JSON.
 
json neograph::messages_to_json (const std::vector< ChatMessage > &messages)
 Convert a vector of ChatMessages to OpenAI-compatible JSON format.
 
ChatMessage neograph::parse_response_message (const json &choice)
 Parse an OpenAI API response choice into a ChatMessage.
 
void neograph::to_json (json &j, const ChatMessage &msg)
 Serialize a ChatMessage to JSON.
 
void neograph::to_json (json &j, const ToolCall &tc)
 Serialize a ToolCall to JSON.
 
json neograph::tools_to_json (const std::vector< ChatTool > &tools)
 Convert a vector of ChatTools to OpenAI-compatible JSON format.
 

Detailed Description

Foundation types for NeoGraph: messages, tool calls, and LLM completions.

Defines the core data structures shared across all NeoGraph modules, including ChatMessage, ToolCall, ChatCompletion, and their JSON serialization helpers (ADL-based, nlohmann/json compatible).

Definition in file types.h.

Function Documentation

◆ from_json() [1/2]

void neograph::from_json ( const json &  j,
ChatMessage msg 
)
inline

Deserialize a ChatMessage from JSON.

Parameters
[in]jSource JSON object.
[out]msgTarget ChatMessage.

Definition at line 112 of file types.h.

References neograph::ChatMessage::content, neograph::ChatMessage::image_urls, neograph::ChatMessage::role, neograph::ChatMessage::tool_call_id, neograph::ChatMessage::tool_calls, and neograph::ChatMessage::tool_name.

◆ from_json() [2/2]

void neograph::from_json ( const json &  j,
ToolCall tc 
)
inline

Deserialize a ToolCall from JSON.

Parameters
[in]jSource JSON object.
[out]tcTarget ToolCall.

Definition at line 84 of file types.h.

References neograph::ToolCall::arguments, neograph::ToolCall::id, and neograph::ToolCall::name.

◆ messages_to_json()

json neograph::messages_to_json ( const std::vector< ChatMessage > &  messages)
inline

Convert a vector of ChatMessages to OpenAI-compatible JSON format.

Handles tool call messages, tool result messages, and multi-modal messages (text + images in OpenAI Vision format).

Parameters
messagesVector of ChatMessage objects to convert.
Returns
JSON array in OpenAI messages format.

Definition at line 140 of file types.h.

References neograph::messages_to_json().

Referenced by neograph::messages_to_json().

◆ parse_response_message()

ChatMessage neograph::parse_response_message ( const json &  choice)
inline

Parse an OpenAI API response choice into a ChatMessage.

Extracts the message content, role, and any tool calls from the choices[n] object of an OpenAI completion response.

Parameters
choiceA single choice object from the OpenAI response (must contain "message").
Returns
Parsed ChatMessage with role, content, and tool_calls populated.
Exceptions
json::exceptionIf required fields are missing.

Definition at line 210 of file types.h.

References neograph::ToolCall::arguments, neograph::ChatMessage::content, neograph::ToolCall::id, neograph::ToolCall::name, neograph::parse_response_message(), neograph::ChatMessage::role, and neograph::ChatMessage::tool_calls.

Referenced by neograph::parse_response_message().

◆ to_json() [1/2]

void neograph::to_json ( json &  j,
const ChatMessage msg 
)
inline

Serialize a ChatMessage to JSON.

Parameters
[out]jTarget JSON object.
[in]msgChatMessage to serialize.

Definition at line 93 of file types.h.

References neograph::ChatMessage::content, neograph::ChatMessage::image_urls, neograph::ChatMessage::role, neograph::ChatMessage::tool_call_id, neograph::ChatMessage::tool_calls, and neograph::ChatMessage::tool_name.

◆ to_json() [2/2]

void neograph::to_json ( json &  j,
const ToolCall tc 
)
inline

Serialize a ToolCall to JSON.

Parameters
[out]jTarget JSON object.
[in]tcToolCall to serialize.

Definition at line 77 of file types.h.

References neograph::ToolCall::arguments, neograph::ToolCall::id, and neograph::ToolCall::name.

◆ tools_to_json()

json neograph::tools_to_json ( const std::vector< ChatTool > &  tools)
inline

Convert a vector of ChatTools to OpenAI-compatible JSON format.

Parameters
toolsVector of ChatTool objects to convert.
Returns
JSON array in OpenAI tool definition format.

Definition at line 185 of file types.h.

References neograph::tools_to_json().

Referenced by neograph::tools_to_json().