{"id":50454122,"url":"https://github.com/mizcausevic-dev/zig-agent-graph-db","last_synced_at":"2026-06-01T01:05:40.098Z","repository":{"id":357462749,"uuid":"1236305333","full_name":"mizcausevic-dev/zig-agent-graph-db","owner":"mizcausevic-dev","description":"In-memory directed graph DB in Zig for AI agent context graphs. Typed nodes (agent, tool, fact, result, citation), labeled edges, BFS traversal, JSON serialization. Pure Zig stdlib, zero deps.","archived":false,"fork":false,"pushed_at":"2026-05-12T21:42:51.000Z","size":31,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-12T23:22:41.851Z","etag":null,"topics":["agent","ai-agents","data-structures","embedded","graph","graph-database","platform-engineering","systems-programming","zig","ziglang"],"latest_commit_sha":null,"homepage":"https://github.com/mizcausevic-dev/zig-agent-graph-db","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"agpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mizcausevic-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-12T06:09:30.000Z","updated_at":"2026-05-12T21:42:56.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/mizcausevic-dev/zig-agent-graph-db","commit_stats":null,"previous_names":["mizcausevic-dev/zig-agent-graph-db"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/mizcausevic-dev/zig-agent-graph-db","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fzig-agent-graph-db","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fzig-agent-graph-db/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fzig-agent-graph-db/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fzig-agent-graph-db/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mizcausevic-dev","download_url":"https://codeload.github.com/mizcausevic-dev/zig-agent-graph-db/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mizcausevic-dev%2Fzig-agent-graph-db/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33755379,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-05-31T02:00:06.040Z","response_time":95,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agent","ai-agents","data-structures","embedded","graph","graph-database","platform-engineering","systems-programming","zig","ziglang"],"created_at":"2026-06-01T01:05:40.016Z","updated_at":"2026-06-01T01:05:40.087Z","avatar_url":"https://github.com/mizcausevic-dev.png","language":"Zig","funding_links":[],"categories":[],"sub_categories":[],"readme":"# zig-agent-graph-db\n\nAn in-memory directed-graph data structure in **Zig**, designed for the kind of context graph an AI agent builds during a task: nodes are typed entities (agent, tool, fact, result, citation), edges are labeled relationships (`uses`, `produces`, `references`, `supports`, `contradicts`).\n\nZero dependencies beyond the Zig standard library. Compiles to a tiny native binary (about 200 KB stripped on Linux x86_64).\n\n## Why a custom graph?\n\nGeneral-purpose graph libraries are overpowered for the working memory of a single agent task. This crate stays small, owns its memory, and exposes only the operations an agent actually needs:\n\n- `addNode(label, kind) -\u003e id` — entity insertion\n- `addEdge(from, to, label) -\u003e id` — labeled relationship\n- `neighbors(id) -\u003e []id` — immediate successors\n- `bfs(start) -\u003e []id` — full traversal order\n- `toJson(writer)` — durable serialization\n\n`NodeKind` is a closed enum (`agent`, `tool`, `fact`, `result`, `citation`, `other`) so traversal code can branch cleanly without a string match.\n\n## Quickstart\n\n```bash\nzig build run\n```\n\nOutput:\n\n```\nagent_graph_db: 6 nodes, 5 edges\n\nBFS order from agent:\n  [agent] agent:incident-triage\n  [tool] mcp.search-tool\n  [tool] mcp.kb-lookup\n  [fact] cve-2026-001\n  [citation] nist-sp-800-53\n  [result] risk-score:high\n\nJSON serialization:\n{\"nodes\":[...],\"edges\":[...]}\n```\n\nThat's a complete agent reasoning trace: agent invoked two tools, each tool produced one downstream node, and a derived `result` node was supported by one of the facts.\n\n## Library usage\n\n```zig\nconst graph = @import(\"zig-agent-graph-db\");\n\nvar g = graph.Graph.init(allocator);\ndefer g.deinit();\n\nconst agent = try g.addNode(\"agent:foo\", .agent);\nconst tool = try g.addNode(\"mcp.search\", .tool);\nconst fact = try g.addNode(\"fact:x\", .fact);\n_ = try g.addEdge(agent, tool, \"uses\");\n_ = try g.addEdge(tool, fact, \"produces\");\n\nconst order = try g.bfs(agent, allocator);\ndefer allocator.free(order);\n// order is [agent, tool, fact]\n```\n\n## Tests\n\nSeven unit tests cover:\n\n- `addNode` assigns sequential ids and counts nodes correctly\n- `addEdge` returns `error.UnknownNode` when either endpoint is missing\n- `neighbors(id)` returns all immediate successors\n- `bfs(start)` visits all reachable nodes; unreachable nodes are not included\n- `bfs(unknown_id)` returns `error.UnknownNode`\n- `toJson` emits a structure containing both `nodes` and `edges` arrays with the expected labels\n- `NodeKind.fromString` and `NodeKind.toString` round-trip cleanly for every variant\n\n```bash\nzig build test --summary all\n```\n\n## Build artifacts\n\n| Mode | Approximate size |\n|---|---|\n| `zig build` (debug) | ~500 KB |\n| `zig build -Doptimize=ReleaseSafe` | ~250 KB |\n| `zig build -Doptimize=ReleaseSmall` | ~80 KB |\n\n## Memory ownership\n\nThe graph owns every node label and edge label allocation. `deinit()` frees all of them. Caller-allocated slices returned by `neighbors()` and `bfs()` are caller-owned — free with the same allocator you passed.\n\n## Roadmap\n\n- DFS in addition to BFS\n- Reverse edges / `predecessors(id)`\n- JSON `fromJson` (parse) — currently only `toJson` (serialize) is implemented\n- Shortest path between two nodes (Dijkstra over uniform edges)\n\n## License\n\nAGPL-3.0.\n\n---\n\n**Connect:** [LinkedIn](https://www.linkedin.com/in/mirzacausevic/) · [Kinetic Gain](https://kineticgain.com) · [Medium](https://medium.com/@mizcausevic/) · [Skills](https://mizcausevic.com/skills/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmizcausevic-dev%2Fzig-agent-graph-db","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmizcausevic-dev%2Fzig-agent-graph-db","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmizcausevic-dev%2Fzig-agent-graph-db/lists"}