agent-context-graph 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,186 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ #uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ #poetry.lock
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ #pdm.lock
113
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114
+ # in version control.
115
+ # https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116
+ .pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121
+ __pypackages__/
122
+
123
+ # Celery stuff
124
+ celerybeat-schedule
125
+ celerybeat.pid
126
+
127
+ # SageMath parsed files
128
+ *.sage.py
129
+
130
+ # Environments
131
+ .env
132
+ .venv
133
+ env/
134
+ venv/
135
+ ENV/
136
+ env.bak/
137
+ venv.bak/
138
+
139
+ # Spyder project settings
140
+ .spyderproject
141
+ .spyproject
142
+
143
+ # Rope project settings
144
+ .ropeproject
145
+
146
+ # mkdocs documentation
147
+ /site
148
+
149
+ # mypy
150
+ .mypy_cache/
151
+ .dmypy.json
152
+ dmypy.json
153
+
154
+ # Pyre type checker
155
+ .pyre/
156
+
157
+ # pytype static type analyzer
158
+ .pytype/
159
+
160
+ # Cython debug symbols
161
+ cython_debug/
162
+
163
+ # PyCharm
164
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
165
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
166
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
167
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
168
+ #.idea/
169
+
170
+ # Ruff stuff:
171
+ .ruff_cache/
172
+
173
+ # PyPI configuration file
174
+ .pypirc
175
+
176
+
177
+ # VS Code
178
+ .vscode/
179
+
180
+
181
+ # Local agent hook configuration
182
+ /.codex/
183
+ /.claude/settings.local.json
184
+
185
+ # Project specific files
186
+ /enterprise-context/sic-agent/sic-scrapper/output/*
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Memgraph
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,379 @@
1
+ Metadata-Version: 2.4
2
+ Name: agent-context-graph
3
+ Version: 0.1.0
4
+ Summary: Connect agent SDKs to context-graph components (actions-graph, skills-graph, etc.)
5
+ License: MIT
6
+ License-File: LICENSE
7
+ Classifier: Programming Language :: Python :: 3.10
8
+ Classifier: Programming Language :: Python :: 3.11
9
+ Classifier: Programming Language :: Python :: 3.12
10
+ Classifier: Programming Language :: Python :: 3.13
11
+ Requires-Python: >=3.10
12
+ Provides-Extra: claude
13
+ Requires-Dist: claude-agent-sdk>=0.1.0; extra == 'claude'
14
+ Provides-Extra: openai
15
+ Requires-Dist: openai-agents>=0.1.0; extra == 'openai'
16
+ Provides-Extra: test
17
+ Requires-Dist: pytest-asyncio>=0.24.0; extra == 'test'
18
+ Requires-Dist: pytest>=9.0.3; extra == 'test'
19
+ Description-Content-Type: text/markdown
20
+
21
+ # Agent Context Graph
22
+
23
+ Connect any agent SDK to any context-graph component.
24
+
25
+ Agent Context Graph is a lightweight adapter layer that decouples SDK-specific hooks from graph storage. It routes a common event protocol from SDK adapters to graph connectors, so you can mix and match SDKs and graph components.
26
+
27
+ ```
28
+ SDK Adapter -> Event Protocol -> Graph Connector(s)
29
+ (Claude, (ToolStart, (SkillGraphConnector,
30
+ OpenAI) ToolEnd, ...) custom connectors, ...)
31
+ ```
32
+
33
+ ## Installation
34
+
35
+ ```bash
36
+ pip install agent-context-graph
37
+ ```
38
+
39
+ With SDK adapters:
40
+
41
+ ```bash
42
+ pip install agent-context-graph[claude]
43
+ pip install agent-context-graph[openai]
44
+ ```
45
+
46
+ Graph connectors live in the graph packages that persist the data. For the skills graph connector:
47
+
48
+ ```bash
49
+ pip install skills-graph[agent-context-graph]
50
+ ```
51
+
52
+ ## Quick Start
53
+
54
+ ### Claude Agent SDK
55
+
56
+ ```python
57
+ from agent_context_graph import AgentLink
58
+ from agent_context_graph.adapters.claude import ClaudeAdapter
59
+ from claude_agent_sdk import ClaudeAgentOptions, query
60
+ from skills_graph import SkillGraph
61
+ from skills_graph.connector import SkillGraphConnector
62
+
63
+ # 1. Set up graph storage
64
+ skills = SkillGraph()
65
+ skills.setup()
66
+
67
+ # 2. Wire up the link
68
+ link = AgentLink()
69
+ link.add_connector(SkillGraphConnector(skills))
70
+
71
+ # 3. Create adapter
72
+ adapter = ClaudeAdapter(
73
+ link,
74
+ session_id="my-session",
75
+ session_kwargs={"model": "claude-sonnet-4-20250514", "tags": ["review"]},
76
+ )
77
+
78
+ # 4. Use with Claude Agent SDK
79
+ async for message in query(
80
+ prompt="Review the available skills",
81
+ options=ClaudeAgentOptions(hooks=adapter.get_sdk_hooks()),
82
+ ):
83
+ print(message)
84
+ ```
85
+
86
+ ### OpenAI Agents SDK
87
+
88
+ ```python
89
+ from agent_context_graph import AgentLink
90
+ from agent_context_graph.adapters.openai import OpenAIAdapter
91
+ from agents import Agent, Runner, function_tool
92
+ from skills_graph import SkillGraph
93
+ from skills_graph.connector import SkillGraphConnector
94
+
95
+ # 1. Set up graph storage
96
+ skills = SkillGraph()
97
+ skills.setup()
98
+
99
+ # 2. Define a tool whose name matches the SkillGraphConnector defaults
100
+ @function_tool
101
+ def get_skill(name: str) -> str:
102
+ skill = skills.get_skill(name)
103
+ if skill is None:
104
+ return f"Skill '{name}' not found."
105
+ return f"{skill.name}: {skill.description}\n{skill.content}"
106
+
107
+ # 3. Wire up the link
108
+ link = AgentLink()
109
+ link.add_connector(SkillGraphConnector(skills))
110
+
111
+ # 4. Create adapter
112
+ adapter = OpenAIAdapter(
113
+ link,
114
+ session_id="my-session",
115
+ session_kwargs={"model": "gpt-4o-mini"},
116
+ )
117
+
118
+ # 5. Run with hooks
119
+ agent = Agent(
120
+ name="Skill Assistant",
121
+ instructions="Use get_skill when the user asks for a named skill.",
122
+ tools=[get_skill],
123
+ model="gpt-4o-mini",
124
+ )
125
+ result = await Runner.run(
126
+ agent,
127
+ "Get the skill called 'cypher-basics'",
128
+ hooks=adapter.get_sdk_hooks(),
129
+ )
130
+
131
+ # 6. Signal end (OpenAI SDK doesn't have a stop hook)
132
+ adapter.end_session()
133
+ ```
134
+
135
+ ### Command Hook Runtimes
136
+
137
+ Some agent applications run hooks as external commands instead of in-process SDK callbacks. Runtime adapters should keep the product-specific JSON mapping at the edge, emit the shared `Event` protocol, and leave graph persistence in connectors such as `SkillGraphConnector`.
138
+
139
+ The installed command is runtime-dispatched:
140
+
141
+ ```bash
142
+ agent-context-graph hook <command> [options]
143
+ ```
144
+
145
+ Implemented:
146
+
147
+ | Runtime | Adapter | Hook Shape |
148
+ |---------|---------|------------|
149
+ | OpenAI Codex | `CodexHooksAdapter` | Command receives one JSON object on `stdin` |
150
+
151
+ Planned:
152
+
153
+ | Runtime | Adapter | Notes |
154
+ |---------|---------|-------|
155
+ | Claude Code | `ClaudeCodeHooksAdapter` | TODO: command-hook adapter for Claude Code JSON input/output and `.claude/settings.local.json` setup |
156
+
157
+ ### OpenAI Codex Hooks
158
+
159
+ Codex hook configuration is local environment wiring, so this repository ignores `.codex/`. Each developer should create their own local `.codex` files or use a user-level Codex config.
160
+
161
+ 1. Make `skills-graph` able to reach Memgraph, then initialize and seed your skill graph once:
162
+
163
+ ```bash
164
+ export MEMGRAPH_URL="bolt://localhost:7687"
165
+ export MEMGRAPH_USER=""
166
+ export MEMGRAPH_PASSWORD=""
167
+ ```
168
+
169
+ ```python
170
+ from skills_graph import SkillGraph
171
+
172
+ skills = SkillGraph()
173
+ skills.setup()
174
+ ```
175
+
176
+ 2. Install the hook command and the graph connector in the same Python environment:
177
+
178
+ ```bash
179
+ python -m venv ~/.venvs/agent-context-graph-hooks
180
+ ~/.venvs/agent-context-graph-hooks/bin/python -m pip install \
181
+ "agent-context-graph" \
182
+ "skills-graph[agent-context-graph]"
183
+ ```
184
+
185
+ For source development in this workspace, use this command instead of the venv binary:
186
+
187
+ ```bash
188
+ cd /path/to/ai-toolkit
189
+ uv run --package skills-graph --extra agent-context-graph \
190
+ python -m agent_context_graph.cli hook run codex --connector skills-graph
191
+ ```
192
+
193
+ 3. Generate private Codex hook config in the workspace:
194
+
195
+ ```bash
196
+ agent-context-graph hook init codex --connector skills-graph
197
+ ```
198
+
199
+ For source development in this workspace:
200
+
201
+ ```bash
202
+ uv run --package skills-graph --extra agent-context-graph \
203
+ python -m agent_context_graph.cli hook init codex --connector skills-graph
204
+ ```
205
+
206
+ The wizard writes local, ignored files:
207
+
208
+ ```text
209
+ .codex/config.toml
210
+ .codex/hooks.json
211
+ ```
212
+
213
+ It refuses to overwrite existing generated files unless you pass `--force`.
214
+
215
+ The generated config enables Codex hooks and points all supported Codex hook events at a command like:
216
+
217
+ ```bash
218
+ agent-context-graph hook run codex --connector skills-graph
219
+ ```
220
+
221
+ The resulting `.codex/hooks.json` has this shape:
222
+
223
+ ```json
224
+ {
225
+ "hooks": {
226
+ "SessionStart": [
227
+ {
228
+ "matcher": "startup|resume|clear",
229
+ "hooks": [{ "type": "command", "command": "COMMAND", "timeout": 30 }]
230
+ }
231
+ ],
232
+ "UserPromptSubmit": [
233
+ {
234
+ "hooks": [{ "type": "command", "command": "COMMAND", "timeout": 30 }]
235
+ }
236
+ ],
237
+ "PreToolUse": [
238
+ {
239
+ "matcher": "*",
240
+ "hooks": [{ "type": "command", "command": "COMMAND", "timeout": 30 }]
241
+ }
242
+ ],
243
+ "PostToolUse": [
244
+ {
245
+ "matcher": "*",
246
+ "hooks": [{ "type": "command", "command": "COMMAND", "timeout": 30 }]
247
+ }
248
+ ],
249
+ "PermissionRequest": [
250
+ {
251
+ "hooks": [{ "type": "command", "command": "COMMAND", "timeout": 30 }]
252
+ }
253
+ ],
254
+ "Stop": [
255
+ {
256
+ "hooks": [{ "type": "command", "command": "COMMAND", "timeout": 30 }]
257
+ }
258
+ ]
259
+ }
260
+ }
261
+ ```
262
+
263
+ The adapter records Codex `SessionStart`, `UserPromptSubmit`, `PreToolUse`, `PostToolUse`, `PermissionRequest`, and `Stop` payloads. MCP tool names such as `mcp__skills__get_skill` are normalized by `skills-graph` to the underlying `get_skill` operation.
264
+
265
+ Smoke test the command:
266
+
267
+ ```bash
268
+ printf '{"hook_event_name":"Stop","session_id":"test"}' | COMMAND
269
+ ```
270
+
271
+ The expected output is:
272
+
273
+ ```json
274
+ {"continue": true}
275
+ ```
276
+
277
+ ### Multiple Graph Components
278
+
279
+ ```python
280
+ from agent_context_graph import AgentLink
281
+ from agent_context_graph.adapters.claude import ClaudeAdapter
282
+ from skills_graph import SkillGraph
283
+ from skills_graph.connector import SkillGraphConnector
284
+
285
+ skills = SkillGraph()
286
+
287
+ link = AgentLink()
288
+ link.add_connector(SkillGraphConnector(skills))
289
+ link.add_connector(MyGraphConnector(...))
290
+
291
+ adapter = ClaudeAdapter(link, session_id="s-1")
292
+ hooks = adapter.get_sdk_hooks()
293
+ ```
294
+
295
+ Connectors are owned by the graph packages because each graph package knows its own schema and persistence rules.
296
+
297
+ ## Architecture
298
+
299
+ ### Event Protocol
300
+
301
+ All SDK adapters emit SDK-agnostic `Event` dataclasses:
302
+
303
+ | Event | When |
304
+ |-------|------|
305
+ | `SessionStartEvent` | Agent session begins |
306
+ | `SessionEndEvent` | Agent session ends |
307
+ | `ToolStartEvent` | Before tool/function call |
308
+ | `ToolEndEvent` | After tool/function returns |
309
+ | `AgentStartEvent` | Agent/subagent begins |
310
+ | `AgentEndEvent` | Agent/subagent finishes |
311
+ | `LLMStartEvent` | Before LLM call |
312
+ | `LLMEndEvent` | After LLM response |
313
+ | `HandoffEvent` | Agent hands off to another |
314
+ | `MessageEvent` | User/assistant/system message |
315
+ | `ErrorOccurredEvent` | Error during execution |
316
+
317
+ ### SDK Adapters
318
+
319
+ | Adapter | SDK | Hook Mechanism |
320
+ |---------|-----|----------------|
321
+ | `ClaudeAdapter` | Claude Agent SDK | Dict of `HookMatcher` callbacks |
322
+ | `OpenAIAdapter` | OpenAI Agents SDK | `RunHooksBase` subclass |
323
+ | `CodexHooksAdapter` | OpenAI Codex | Command hooks reading JSON from stdin |
324
+
325
+ ### Graph Connectors
326
+
327
+ | Connector | Graph Component | Events Handled |
328
+ |-----------|----------------|----------------|
329
+ | `SkillGraphConnector` | skills-graph | Tool events matching skill access/search operations |
330
+
331
+ Additional graph connectors should live in the packages that own those graph schemas.
332
+
333
+ ### Adding a New SDK
334
+
335
+ Implement `SDKAdapter`:
336
+
337
+ ```python
338
+ from agent_context_graph import AgentLink, ToolStartEvent
339
+ from agent_context_graph.protocols import SDKAdapter
340
+
341
+ class MySDKAdapter(SDKAdapter):
342
+ def __init__(self, link: AgentLink, session_id: str):
343
+ self._link = link
344
+ self._session_id = session_id
345
+
346
+ def get_sdk_hooks(self):
347
+ # Return whatever your SDK expects.
348
+ ...
349
+
350
+ def _on_tool_call(self, name, args):
351
+ self._link.emit(
352
+ ToolStartEvent(
353
+ session_id=self._session_id,
354
+ tool_name=name,
355
+ tool_input=args,
356
+ )
357
+ )
358
+ ```
359
+
360
+ ### Adding a New Graph Component
361
+
362
+ Implement `GraphConnector` in the graph package:
363
+
364
+ ```python
365
+ from agent_context_graph import EventType
366
+ from agent_context_graph.protocols import GraphConnector
367
+
368
+ class MyGraphConnector(GraphConnector):
369
+ def supports(self, event):
370
+ return event.event_type in {EventType.TOOL_START, EventType.TOOL_END}
371
+
372
+ def on_event(self, event):
373
+ # Write to your graph component.
374
+ ...
375
+ ```
376
+
377
+ ## License
378
+
379
+ MIT