HN
Hacker News • 24일 전
크로스 플랫폼 임베디드 C 언어 AI 에이전트 라이브러리 Adam
IMP 7/10
핵심 요약
해커뉴스에 'Adam'이라는 C 언어 기반의 임베디드 AI 에이전트 라이브러리가 소개되었습니다. 이 라이브러리는 하나의 헤더 파일 포함(#include)만으로 도구 호출, 메모리, 세션, 음성 처리 등 완전한 에이전트 루프를 제공하는 것이 특징입니다. 클라우드 API는 물론 로컬 모델까지 동일한 인터페이스로 지원하며, 모바일과 웹(WASM)을 포함한 다양한 운영체제에서 완벽하게 컴파일되어 활용도가 높습니다.
번역된 본문
Adam: 임베디드 가능한 C 언어 기반 AI 에이전트 라이브러리
Adam은 C 언어로 작성된 임베디드 AI 에이전트 라이브러리입니다. 단 하나의 #include만으로 도구(Tool) 호출, 메모리, 세션 관리, 음성 처리, 스트리밍, 구조화된 출력(Structured output)을 포함하는 완벽한 에이전트 루프를 제공합니다. 클라우드 API(Anthropic, OpenAI, Google Gemini, Groq, Together, xAI)와 로컬 모델(llama.cpp)을 동일한 인터페이스를 통해 사용할 수 있으며, macOS, Linux, Windows, iOS, Android, WASM 환경에서 모두 컴파일 가능합니다.
빠른 시작
#include "adam.h"
int main(void) {
adam_init();
adam_settings_t *s = adam_create_settings();
adam_settings_set_provider(s, ADAM_API_ANTHROPIC, getenv("ANTHROPIC_API_KEY"), "claude-sonnet-4-20250514");
adam_history_t *h = adam_history_create();
adam_run_result_t r = adam_run(s, h, "What is the capital of France?");
printf("%s\n", r.final_response); // "The capital of France is Paris."
adam_run_result_free(&r);
adam_history_destroy(h);
adam_settings_destroy(s);
adam_cleanup();
}
빌드 방법
make deps: llama.cpp 및 whisper.cpp 빌드make all: libadam.a 빌드make test: 161개의 테스트 실행 (ASan 및 UBSan 적용)
주요 기능
- 에이전트 루프(Agent loop): 최종 응답이 나올 때까지 자동 반복하며 도구를 호출
- 3개의 기본 제공자(Providers): Anthropic, OpenAI, Google Gemini 지원 및 호환되는 API, 로컬 GGUF(llama.cpp) 지원
- 로컬 비전(Vision): llama.cpp와 mmproj를 통한 멀티모달 이미지 이해 (Gemma 3, LLaVA 등 지원)
- 이미지 생성: Gemini 이미지 모델을 통한 네이티브 이미지 출력
- 데이터베이스 확장: SQLite 및 PostgreSQL 확장 기능을 통해 Adam을 SQL 함수로 내장하여 동일한 데이터베이스 쿼리에 활용 가능
- 13개 내장 도구: 파일 입출력, 셸, 계산기, SQL, 웹 fetch/search, HTTP POST, 메모리, 리서치, 멀티 에이전트 등
- 장기 기억(Long-term memory): SQLite 기반의 하이브리드 BM25 및 벡터 검색(sqlite-memory + sqlite-vector) 제공
- 세션 지속성: UUIDv7 키를 사용한 대화 저장 및 불러오기
- 텔레그램 봇: 텍스트, 음성, 이미지, 도구, 메모리를 활용하는 완벽한 텔레그램 연동 기능
- 음성 처리: STT(Whisper 클라우드/로컬) 및 TTS(클라우드/시스템), 전체 오디오 파이프라인 지원
- 스트리밍: 콜백을 통한 실시간 토큰 전달
- 구조화된 출력: 검증 및 재시도 로직이 포함된
adam_run_json()제공 - 진화 루프(Evolution loop): 반복, 점수 책정, 전략 개선을 통해 스스로 발전하는 에이전트
- 리서치 모드: 자율적인 다중 반복 정보 수집 및 보고서 종합
- 멀티 에이전트: 에이전트 A가 독립적인 설정과 도구를 가진 에이전트 B를 도구로 호출
- 가드레일(Guardrails): 전송 전 및 수신 후 검증 콜백
- 응답 캐시: 모델 및 메시지 기록을 키로 사용하는 LRU 해시 테이블
- 기록 관리: 복제, 요약(LLM 기반 압축), 토큰 추정
- 스레드 풀: 작업 큐를 활용한 동시성 에이전트 실행
- 파일시스템 샌드박스: 명시적으로 허용된 디렉토리로만 도구 사용 제한
- 크로스 플랫폼: macOS, Linux, Windows, iOS, Android, WASM(Emscripten) 지원
- 아레나 할당자(Arena allocator): 반복 시 메모리 누수가 없는 자동 정리 기능
빌드 명령어
make deps: llama.cpp, whisper.cpp 빌드 (Linux에서는 mbedtls/curl 포함)make all: libadam.a 빌드make test: 유닛 테스트 빌드 및 실행 (ASan + UBSan)make chat: 대화형 텍스트 채팅 (클라우드 API)make chat GGUF=models/model.gguf: 대화형 텍스트 채팅 (로컬)make vision GGUF=models/model.gguf MMPROJ=models/mmproj.gguf: 로컬 비전 테스트make talk: 음성 에이전트 (클라우드)make talk LOCAL=1: 음성 에이전트 (완전 로컬)make memory: 메모리 시스템 테스트make clean: 모든 빌드 아티팩트 제거
API 참조
모든 함수, 타입 및 콜백에 대한 전체 API 문서는 API.md에서 확인할 수 있습니다.
사용 예시
adam_settings_t *s = adam_create_settings();
adam_settings_set_provider(s, ADAM_API_ANTHROPIC, api_key, "claude-sonnet-4-20250514");
adam_history_t *h = adam_history_create();
adam_run_result_t r = adam_run(s, h, "Explain quantum entanglement simply.");
printf("%s\n", r.final_response);
adam_run_result_free(&r);
// 대화 이어하기 - 기록(history)이 자동으로 유지됩니다
r = adam_run(s, h, "Can you give an analogy?");
printf("%s\n", r.final_response);
adam_run_result_free(&r);
adam_history_destroy(h);
adam_settings_destroy(s);
더 많은 예제는 examples/ 디렉토리에서 확인할 수 있습니다:
- simple-conversation: 멀티턴 채팅...
원문 보기 (영어)
Adam Embeddable AI agent library in C. Adam gives you a complete agent loop: tool calling, memory, sessions, voice, streaming, structured output, in one #include . Works with cloud APIs (Anthropic, OpenAI, Google Gemini, Groq, Together, xAI) and local models (llama.cpp) through the same interface. Compiles on macOS, Linux, Windows, iOS, Android, and WASM. Quick Start #include "adam.h" int main ( void ) { adam_init (); adam_settings_t * s = adam_create_settings (); adam_settings_set_provider ( s , ADAM_API_ANTHROPIC , getenv ( "ANTHROPIC_API_KEY" ), "claude-sonnet-4-20250514" ); adam_history_t * h = adam_history_create (); adam_run_result_t r = adam_run ( s , h , "What is the capital of France?" ); printf ( "%s\n" , r . final_response ); // "The capital of France is Paris." adam_run_result_free ( & r ); adam_history_destroy ( h ); adam_settings_destroy ( s ); adam_cleanup (); } make deps # build llama.cpp + whisper.cpp make all # build libadam.a make test # run 161 tests (ASan + UBSan) Features Feature Description Agent loop Tool calling with automatic iteration until final response Three providers Anthropic, OpenAI, Google Gemini + any compatible API + local GGUF via llama.cpp Local vision Multimodal image understanding via llama.cpp + mmproj (Gemma 3, LLaVA, etc.) Image generation Native image output via Gemini image models (gemini-3.1-flash-image-preview) Database extensions SQLite and PostgreSQL extensions — embed Adam as SQL functions that query the same database 13 built-in tools File I/O, shell, calculator, SQL, web fetch/search, HTTP POST, memory, research, multi-agent Long-term memory Hybrid BM25 + vector search via SQLite (sqlite-memory + sqlite-vector) Session persistence Save/load conversations with UUIDv7 keys Telegram bot Full-featured Telegram integration with text, voice, images, tools, and memory Voice STT (Whisper cloud/local) + TTS (cloud/system) + full audio pipeline Streaming Real-time token delivery via callback Structured output adam_run_json() with validation and retry Evolution loop Self-improving agent: iterate, score, refine strategy Research mode Autonomous multi-iteration information gathering with report synthesis Multi-agent Agent A invokes Agent B as a tool, with independent settings/tools Guardrails Pre-send and post-receive validation callbacks Response cache LRU hash table keyed on model + message history History management Clone, summarize (LLM-based compression), token estimation Thread pool Concurrent agent execution with job queue Filesystem sandbox Tools restricted to explicitly allowed directories Cross-platform macOS, Linux, Windows, iOS, Android, WASM (Emscripten) Arena allocator Zero-leak per-iteration memory with automatic cleanup Build make deps # Build llama.cpp, whisper.cpp (+ mbedtls/curl on Linux) make all # Build libadam.a make test # Build & run unit tests (ASan + UBSan) make chat # Interactive text chat (cloud API) make chat GGUF=models/model.gguf # Interactive text chat (local) make vision GGUF=models/model.gguf MMPROJ=models/mmproj.gguf # Local vision test make talk # Voice agent (cloud) make talk LOCAL=1 # Voice agent (fully local) make memory # Memory system tests make clean # Remove all build artifacts API Reference Full API documentation with every function, type, and callback: API.md Examples adam_settings_t * s = adam_create_settings (); adam_settings_set_provider ( s , ADAM_API_ANTHROPIC , api_key , "claude-sonnet-4-20250514" ); adam_history_t * h = adam_history_create (); adam_run_result_t r = adam_run ( s , h , "Explain quantum entanglement simply." ); printf ( "%s\n" , r . final_response ); adam_run_result_free ( & r ); // Continue the conversation — history carries forward r = adam_run ( s , h , "Can you give an analogy?" ); printf ( "%s\n" , r . final_response ); adam_run_result_free ( & r ); adam_history_destroy ( h ); adam_settings_destroy ( s ); More examples are available in the examples/ directory: Example Description simple-conversation Multi-turn chat with a cloud API tool-calling Register a custom tool and let the agent call it local-model Run a local GGUF model via llama.cpp local-vision Image understanding with a local vision model + mmproj google-gemini Use Google Gemini models image-generation Generate images with Gemini sqlite-query Natural language queries on any SQLite database structured-json Get validated JSON output with retry memory Long-term memory with hybrid BM25 + vector search sessions Save and restore conversations streaming Real-time token streaming via callback voice Speech-to-text + agent + text-to-speech pipeline multi-agent Agent A delegates to Agent B as a tool evolution Self-improving agent with scoring loop research Autonomous multi-iteration research with report filesystem-sandbox File and shell tools restricted to allowed directories guardrails Pre-send and post-receive validation response-cache LRU cache for repeated queries thread-pool Concurrent agent execution telegram Telegram bot with text, images, tools, and memory wasm-chat Browser-based chat UI via WebAssembly full-agent All features combined Database Extensions Adam can be embedded directly inside SQLite and PostgreSQL as a SQL extension. The agent can query the same database it's loaded in — ask questions in natural language, get answers from your data. -- SQLite .load adam -- PostgreSQL CREATE EXTENSION adam; -- Configure (both) SELECT adam_config( ' provider ' , ' anthropic ' ); SELECT adam_config( ' api_key ' , ' sk-ant-... ' ); -- Ask about your data — the agent reads the schema and runs SQL SELECT adam_ask( ' How many users signed up last month? ' ); -- → "47 users signed up last month." -- Generate SQL without executing SELECT adam_sql( ' top 5 products by revenue ' ); -- → "SELECT p.name, SUM(oi.quantity * oi.price) AS revenue FROM ..." Function Description adam_config(key, val) Configure provider, API key, model (persisted) adam(msg) Stateless one-shot chat adam_ask(msg) SQL-aware agent — reads schema, queries data, multi-turn adam_sql(question) Generate SQL from natural language adam_create_session() Create session (auto-created on first adam_ask ) adam_get_session() Get current session UUID adam_clear_session() Clear session and history See extensions/sqlite/ and extensions/postgres/ for build instructions. Architecture adam_run() loop: build system prompt (identity + instructions + bootstrap files + memory + datetime) -> check guardrails (on_before_send) -> check cache -> dispatch LLM (mock | local/llama.cpp | remote/HTTP) -> check guardrails (on_after_receive) -> if tool_calls: execute tools -> append results -> loop -> if text: return final response -> auto-save session -> extract memory Platform abstraction : macOS uses NSURLSession, Linux uses libcurl+mbedtls, WASM uses embedder-provided http_fn callback. Memory management : Arena allocators for per-iteration zero-copy work. malloc/free for long-lived structures. Arena-allocated strings are only valid within the current iteration. Feature Gates Define before #include "adam.h" to disable features: Gate Effect ADAM_NO_CURL No libcurl (must provide http_fn callback) ADAM_NO_LOCAL No llama.cpp (no local inference) ADAM_NO_PTHREADS No thread pool, no voice thread ADAM_NO_SQLITE No SQLite (no memory, sessions, or SQL tool) ADAM_NO_VOICE No voice subsystem ADAM_NO_FILESYSTEM No file_read/file_write/list_directory tools ADAM_NO_SHELL No shell_exec tool Dependencies All vendored as git submodules in modules/ : Module Purpose llama.cpp Local LLM inference + GGML compute whisper.cpp Local speech-to-text (shares ggml via symlink) miniaudio Cross-platform audio I/O sqlite Amalgamation build sqlite-memory Hybrid BM25 + vector knowledge store sqlite-vector Vector similarity search mbedtls TLS (Linux only) curl HTTP (Linux only) macOS uses system frameworks (Foundation, Security, Metal, AVFoundation, Accelerate) instead of curl/mbedtls. License MIT