amfs-adapter-postgres 0.2.0__tar.gz → 0.2.1__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.
Files changed (17) hide show
  1. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/.gitignore +3 -0
  2. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/PKG-INFO +2 -2
  3. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/pyproject.toml +4 -3
  4. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/src/amfs_postgres/adapter.py +16 -4
  5. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/src/amfs_postgres/schema.sql +1 -0
  6. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/src/amfs_postgres/__init__.py +0 -0
  7. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/src/amfs_postgres/_fts.py +0 -0
  8. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/src/amfs_postgres/async_adapter.py +0 -0
  9. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/src/amfs_postgres/migrations/001_initial.sql +0 -0
  10. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/src/amfs_postgres/migrations/002_artifact_refs.sql +0 -0
  11. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/src/amfs_postgres/migrations/002_search_indexes.sql +0 -0
  12. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/src/amfs_postgres/migrations/003_knowledge_graph.sql +0 -0
  13. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/src/amfs_postgres/migrations/004_agent_groups.sql +0 -0
  14. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/src/amfs_postgres/migrations/005_configurable_embedding_dim.sql +0 -0
  15. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/src/amfs_postgres/migrations/006_is_artifact.sql +0 -0
  16. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/src/amfs_postgres/migrations/006_outcome_confidence_semantics.sql +0 -0
  17. {amfs_adapter_postgres-0.2.0 → amfs_adapter_postgres-0.2.1}/src/amfs_postgres/tenant_context.py +0 -0
@@ -17,3 +17,6 @@ test.py
17
17
 
18
18
  # pytest temp dirs (created when basetemp lands in the repo)
19
19
  pytest-of-*/
20
+
21
+ # macOS finder metadata, committed three times by accident already.
22
+ .DS_Store
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: amfs-adapter-postgres
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: AMFS Postgres adapter with back-propagation triggers
5
5
  License-Expression: Apache-2.0
6
6
  Requires-Python: >=3.11
7
- Requires-Dist: amfs-core>=0.3.13
7
+ Requires-Dist: amfs-core>=0.3.14
8
8
  Requires-Dist: psycopg-pool>=3.1
9
9
  Requires-Dist: psycopg[binary]<4,>=3.1
@@ -1,12 +1,13 @@
1
1
  [project]
2
2
  name = "amfs-adapter-postgres"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  description = "AMFS Postgres adapter with back-propagation triggers"
5
5
  requires-python = ">=3.11"
6
6
  license = "Apache-2.0"
7
7
  dependencies = [
8
- # 0.3.13 adds the capture fields this adapter now persists and selects back.
9
- "amfs-core>=0.3.13",
8
+ # 0.3.14 adds the capture fields this adapter now persists and selects back,
9
+ # tool_calls among them.
10
+ "amfs-core>=0.3.14",
10
11
  "psycopg[binary]>=3.1,<4",
11
12
  "psycopg-pool>=3.1",
12
13
  ]
@@ -61,6 +61,7 @@ from amfs_core.models import (
61
61
  SearchQuery,
62
62
  SemanticQuery,
63
63
  Tag,
64
+ ToolCall,
64
65
  TraceEntry,
65
66
  )
66
67
 
@@ -603,6 +604,12 @@ class PostgresAdapter(AdapterABC):
603
604
  ALTER TABLE amfs_decision_traces
604
605
  ADD COLUMN IF NOT EXISTS response_text TEXT
605
606
  """)
607
+ # The action side of that pair. Training predicts the action from the
608
+ # request, so a trace carrying only the request is half an example.
609
+ cur.execute("""
610
+ ALTER TABLE amfs_decision_traces
611
+ ADD COLUMN IF NOT EXISTS tool_calls JSONB DEFAULT '[]'
612
+ """)
606
613
  # Entry-to-trace resolution for knowledge lineage. The shared session id
607
614
  # is the only link from a written entry back to the trace that committed
608
615
  # it, since causal_entries records reads rather than writes.
@@ -2539,7 +2546,7 @@ class PostgresAdapter(AdapterABC):
2539
2546
  cur.execute(
2540
2547
  """
2541
2548
  SELECT id, agent_id, session_id, outcome_ref, outcome_type,
2542
- decision_summary, task_input, response_text,
2549
+ decision_summary, task_input, response_text, tool_calls,
2543
2550
  causal_entries, external_contexts,
2544
2551
  query_events, session_started_at, session_ended_at,
2545
2552
  session_duration_ms,
@@ -2567,10 +2574,10 @@ class PostgresAdapter(AdapterABC):
2567
2574
  query_events, session_started_at, session_ended_at,
2568
2575
  session_duration_ms,
2569
2576
  error_events, state_diff, session_metadata, created_at,
2570
- task_input, response_text)
2577
+ task_input, response_text, tool_calls)
2571
2578
  VALUES (%s, %s, %s, %s, %s, %s, %s::jsonb, %s::jsonb,
2572
2579
  %s::jsonb, %s, %s, %s, %s::jsonb, %s::jsonb, %s::jsonb, %s,
2573
- %s, %s)
2580
+ %s, %s, %s::jsonb)
2574
2581
  RETURNING id, created_at
2575
2582
  """,
2576
2583
  (
@@ -2592,6 +2599,7 @@ class PostgresAdapter(AdapterABC):
2592
2599
  trace.created_at,
2593
2600
  trace.task_input,
2594
2601
  trace.response_text,
2602
+ json.dumps([t.model_dump(mode="json") for t in trace.tool_calls]),
2595
2603
  ),
2596
2604
  )
2597
2605
  row = cur.fetchone()
@@ -2624,7 +2632,7 @@ class PostgresAdapter(AdapterABC):
2624
2632
  where = " AND ".join(conditions)
2625
2633
  sql = f"""
2626
2634
  SELECT id, agent_id, session_id, outcome_ref, outcome_type,
2627
- decision_summary, task_input, response_text,
2635
+ decision_summary, task_input, response_text, tool_calls,
2628
2636
  causal_entries, external_contexts,
2629
2637
  query_events, session_started_at, session_ended_at,
2630
2638
  session_duration_ms,
@@ -2827,7 +2835,10 @@ class PostgresAdapter(AdapterABC):
2827
2835
  ec_raw = row["external_contexts"] or []
2828
2836
  qe_raw = row.get("query_events") or []
2829
2837
  ee_raw = row.get("error_events") or []
2838
+ tc_raw = row.get("tool_calls") or []
2830
2839
  sd_raw = row.get("state_diff")
2840
+ if isinstance(tc_raw, str):
2841
+ tc_raw = json.loads(tc_raw)
2831
2842
  if isinstance(ce_raw, str):
2832
2843
  ce_raw = json.loads(ce_raw)
2833
2844
  if isinstance(ec_raw, str):
@@ -2856,6 +2867,7 @@ class PostgresAdapter(AdapterABC):
2856
2867
  decision_summary=row.get("decision_summary"),
2857
2868
  task_input=row.get("task_input"),
2858
2869
  response_text=row.get("response_text"),
2870
+ tool_calls=[ToolCall(**t) for t in tc_raw],
2859
2871
  causal_entries=[TraceEntry(**e) for e in ce_raw],
2860
2872
  external_contexts=[ExternalContext(**c) for c in ec_raw],
2861
2873
  query_events=[QueryEvent(**q) for q in qe_raw],
@@ -60,6 +60,7 @@ CREATE TABLE IF NOT EXISTS amfs_decision_traces (
60
60
  decision_summary TEXT,
61
61
  task_input TEXT,
62
62
  response_text TEXT,
63
+ tool_calls JSONB DEFAULT '[]',
63
64
  causal_entries JSONB DEFAULT '[]',
64
65
  external_contexts JSONB DEFAULT '[]',
65
66
  query_events JSONB DEFAULT '[]',