NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
neograph::AsyncTool Class Referenceabstract

Adapter base class for tools whose work is naturally coroutine-shaped (HTTP fetch, MCP RPC, async DB query). More...

#include <tool.h>

Inheritance diagram for neograph::AsyncTool:
[legend]
Collaboration diagram for neograph::AsyncTool:
[legend]

Public Member Functions

std::string execute (const json &arguments) final
 Sync facade — drives execute_async on a private io_context.
 
virtual asio::awaitable< std::string > execute_async (const json &arguments)=0
 Async work — override this.
 
- Public Member Functions inherited from neograph::Tool
virtual ChatTool get_definition () const =0
 Get the tool definition metadata.
 
virtual std::string get_name () const =0
 Get the tool name.
 

Detailed Description

Adapter base class for tools whose work is naturally coroutine-shaped (HTTP fetch, MCP RPC, async DB query).

Stage 3 / Sem 4.2. The Tool interface is intentionally sync — the Stage 3 plan freezes it so users don't have to migrate every tool to a new signature. AsyncTool keeps that contract: subclasses implement execute_async returning asio::awaitable<std::string> and AsyncTool's sync execute drives it through neograph::async::run_sync. Each invocation gets its own private io_context so the adapter is safe to call from any thread, including from inside an existing run loop.

class FetchTool : public neograph::AsyncTool {
public:
ChatTool get_definition() const override { ... }
std::string get_name() const override { return "fetch"; }
asio::awaitable<std::string>
execute_async(const json& args) override {
auto ex = co_await asio::this_coro::executor;
auto res = co_await neograph::async::async_post(ex, ...);
co_return res.body;
}
};
Adapter base class for tools whose work is naturally coroutine-shaped (HTTP fetch,...
Definition tool.h:88
Tool definition metadata sent to the LLM.
Definition types.h:51

Implementation is in async/run_sync.h via the run_sync template, so this header only needs the asio::awaitable forward declaration.

Definition at line 88 of file tool.h.

Member Function Documentation

◆ execute()

std::string neograph::AsyncTool::execute ( const json &  arguments)
finalvirtual

Sync facade — drives execute_async on a private io_context.

Implemented out-of-line in src/core/tool.cpp so the run_sync helper isn't pulled into every translation unit that includes <neograph/tool.h>.

Implements neograph::Tool.

◆ execute_async()

virtual asio::awaitable< std::string > neograph::AsyncTool::execute_async ( const json &  arguments)
pure virtual

Async work — override this.

Default would infinitely recurse against execute(), so an override is mandatory; left non-pure only because Tool's contract requires execute() to be present and providing both pure-virtual would force every Tool subclass to acknowledge AsyncTool, which we don't want.


The documentation for this class was generated from the following file: