From bc4b342decfc13e7942643890c8435a54c46be52 Mon Sep 17 00:00:00 2001 From: geoyee Date: Sun, 31 May 2026 19:28:04 +0800 Subject: [PATCH 1/2] fix: Fixed the issue of examples failing to compile under MSVC --- examples/context-engineering/context-engineering.cpp | 6 ++++++ examples/memory/memory.cpp | 6 ++++++ examples/multi-agent/multi-agent.cpp | 6 ++++++ examples/shared/chat_loop.h | 12 +++++++++++- examples/shared/logging_callback.h | 10 ++++++++++ examples/shell/shell.cpp | 9 +++++++++ 6 files changed, 48 insertions(+), 1 deletion(-) diff --git a/examples/context-engineering/context-engineering.cpp b/examples/context-engineering/context-engineering.cpp index 0390d32..7f00d26 100644 --- a/examples/context-engineering/context-engineering.cpp +++ b/examples/context-engineering/context-engineering.cpp @@ -15,7 +15,13 @@ #include #include #include + +#if _WIN32 +#include +#define isatty _isatty +#else #include +#endif // _WIN32 static constexpr size_t DEFAULT_MAX_TOOL_CALLS = 1; diff --git a/examples/memory/memory.cpp b/examples/memory/memory.cpp index 7e14aa9..9316357 100644 --- a/examples/memory/memory.cpp +++ b/examples/memory/memory.cpp @@ -15,7 +15,13 @@ #include #include #include + +#if _WIN32 +#include +#define isatty _isatty +#else #include +#endif // _WIN32 using agent_cpp::json; diff --git a/examples/multi-agent/multi-agent.cpp b/examples/multi-agent/multi-agent.cpp index f4e5d44..ea84b0a 100644 --- a/examples/multi-agent/multi-agent.cpp +++ b/examples/multi-agent/multi-agent.cpp @@ -15,7 +15,13 @@ #include #include #include + +#if _WIN32 +#include +#define isatty _isatty +#else #include +#endif // _WIN32 using agent_cpp::json; diff --git a/examples/shared/chat_loop.h b/examples/shared/chat_loop.h index 3d090cc..ae0204c 100644 --- a/examples/shared/chat_loop.h +++ b/examples/shared/chat_loop.h @@ -5,9 +5,15 @@ #include #include #include -#include #include +#if _WIN32 +#include +#define isatty _isatty +#else +#include +#endif // _WIN32 + // Run an interactive chat loop with the given agent. // Reads user input from stdin and prints agent responses to stdout. // The loop continues until the user enters an empty line. @@ -48,3 +54,7 @@ run_chat_loop(agent_cpp::Agent& agent) printf("\nšŸ‘‹ Goodbye!\n"); } + +#if _WIN32 +#undef isatty +#endif // _WIN32 diff --git a/examples/shared/logging_callback.h b/examples/shared/logging_callback.h index 72770a1..82d65aa 100644 --- a/examples/shared/logging_callback.h +++ b/examples/shared/logging_callback.h @@ -4,7 +4,13 @@ #include "tool_result.h" #include #include + +#if _WIN32 +#include +#define isatty _isatty +#else #include +#endif // _WIN32 // Logging callback to display tool execution information. // Shared across examples to provide consistent tool call logging. @@ -47,3 +53,7 @@ class LoggingCallback : public agent_cpp::Callback } } }; + +#if _WIN32 +#undef isatty +#endif // _WIN32 diff --git a/examples/shell/shell.cpp b/examples/shell/shell.cpp index d66d06b..ed1522b 100644 --- a/examples/shell/shell.cpp +++ b/examples/shell/shell.cpp @@ -15,7 +15,16 @@ #include #include #include + +#if _WIN32 +#include +#include +#define isatty _isatty +#define popen _popen +#define pclose _pclose +#else #include +#endif // _WIN32 using agent_cpp::json; using agent_cpp::ToolExecutionSkipped; From 3ea6238faf258405cb9b88bcdcd897c3492f82af Mon Sep 17 00:00:00 2001 From: geoyee Date: Sun, 31 May 2026 21:57:01 +0800 Subject: [PATCH 2/2] fix: Remove non-required items --- examples/context-engineering/context-engineering.cpp | 2 +- examples/memory/memory.cpp | 7 ------- examples/multi-agent/multi-agent.cpp | 7 ------- examples/shared/chat_loop.h | 4 ++-- examples/shared/logging_callback.h | 4 ++-- examples/shell/shell.cpp | 2 +- 6 files changed, 6 insertions(+), 20 deletions(-) diff --git a/examples/context-engineering/context-engineering.cpp b/examples/context-engineering/context-engineering.cpp index 7f00d26..fd148eb 100644 --- a/examples/context-engineering/context-engineering.cpp +++ b/examples/context-engineering/context-engineering.cpp @@ -16,7 +16,7 @@ #include #include -#if _WIN32 +#ifdef _WIN32 #include #define isatty _isatty #else diff --git a/examples/memory/memory.cpp b/examples/memory/memory.cpp index 9316357..3fe4f0c 100644 --- a/examples/memory/memory.cpp +++ b/examples/memory/memory.cpp @@ -16,13 +16,6 @@ #include #include -#if _WIN32 -#include -#define isatty _isatty -#else -#include -#endif // _WIN32 - using agent_cpp::json; class MemoryStore diff --git a/examples/multi-agent/multi-agent.cpp b/examples/multi-agent/multi-agent.cpp index ea84b0a..6d10b97 100644 --- a/examples/multi-agent/multi-agent.cpp +++ b/examples/multi-agent/multi-agent.cpp @@ -16,13 +16,6 @@ #include #include -#if _WIN32 -#include -#define isatty _isatty -#else -#include -#endif // _WIN32 - using agent_cpp::json; class MathAgent; diff --git a/examples/shared/chat_loop.h b/examples/shared/chat_loop.h index ae0204c..fda4c7b 100644 --- a/examples/shared/chat_loop.h +++ b/examples/shared/chat_loop.h @@ -7,7 +7,7 @@ #include #include -#if _WIN32 +#ifdef _WIN32 #include #define isatty _isatty #else @@ -55,6 +55,6 @@ run_chat_loop(agent_cpp::Agent& agent) printf("\nšŸ‘‹ Goodbye!\n"); } -#if _WIN32 +#ifdef _WIN32 #undef isatty #endif // _WIN32 diff --git a/examples/shared/logging_callback.h b/examples/shared/logging_callback.h index 82d65aa..e18e270 100644 --- a/examples/shared/logging_callback.h +++ b/examples/shared/logging_callback.h @@ -5,7 +5,7 @@ #include #include -#if _WIN32 +#ifdef _WIN32 #include #define isatty _isatty #else @@ -54,6 +54,6 @@ class LoggingCallback : public agent_cpp::Callback } }; -#if _WIN32 +#ifdef _WIN32 #undef isatty #endif // _WIN32 diff --git a/examples/shell/shell.cpp b/examples/shell/shell.cpp index ed1522b..e339bf7 100644 --- a/examples/shell/shell.cpp +++ b/examples/shell/shell.cpp @@ -16,7 +16,7 @@ #include #include -#if _WIN32 +#ifdef _WIN32 #include #include #define isatty _isatty