{"id":33902293,"url":"https://github.com/nshkrdotcom/synapse","last_synced_at":"2026-04-08T17:31:33.723Z","repository":{"id":269794595,"uuid":"908471608","full_name":"nshkrdotcom/synapse","owner":"nshkrdotcom","description":"Headless, declarative multi-agent orchestration framework with a domain-agnostic signal bus, workflow engine with Postgres persistence, and configurable agent runtime (ships code review domain).","archived":false,"fork":false,"pushed_at":"2026-04-04T23:45:11.000Z","size":1151,"stargazers_count":42,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"main","last_synced_at":"2026-04-05T01:22:36.751Z","etag":null,"topics":["agent-orchestration","ai","beam","concurrency","elixir","erlang-vm","fault-tolerance","gemini","llm","multi-agent","multi-agent-systems","nshkr-ai-agents","openai","orchestrator","otp","postgres","req","supervision","telemetry","workflows"],"latest_commit_sha":null,"homepage":"https://github.com/nshkrdotcom/synapse","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nshkrdotcom.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":"AGENTS.md","dco":null,"cla":null}},"created_at":"2024-12-26T06:42:52.000Z","updated_at":"2026-04-04T23:45:15.000Z","dependencies_parsed_at":"2025-10-25T03:25:42.274Z","dependency_job_id":null,"html_url":"https://github.com/nshkrdotcom/synapse","commit_stats":null,"previous_names":["nshkrdotcom/axon","nshkrdotcom/synapse"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/nshkrdotcom/synapse","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nshkrdotcom%2Fsynapse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nshkrdotcom%2Fsynapse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nshkrdotcom%2Fsynapse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nshkrdotcom%2Fsynapse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nshkrdotcom","download_url":"https://codeload.github.com/nshkrdotcom/synapse/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nshkrdotcom%2Fsynapse/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31566738,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"ssl_error","status_checked_at":"2026-04-08T14:31:17.202Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-orchestration","ai","beam","concurrency","elixir","erlang-vm","fault-tolerance","gemini","llm","multi-agent","multi-agent-systems","nshkr-ai-agents","openai","orchestrator","otp","postgres","req","supervision","telemetry","workflows"],"created_at":"2025-12-12T00:17:59.371Z","updated_at":"2026-04-08T17:31:33.712Z","avatar_url":"https://github.com/nshkrdotcom.png","language":"Elixir","readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"assets/synapse.svg\" alt=\"Synapse Logo\" width=\"150\"/\u003e\n\u003c/p\u003e\n\n# Synapse\n\n[![Hex.pm](https://img.shields.io/hexpm/v/synapse.svg)](https://hex.pm/packages/synapse)\n[![HexDocs](https://img.shields.io/badge/docs-hexdocs.pm-blue.svg)](https://hexdocs.pm/synapse)\n[![Downloads](https://img.shields.io/hexpm/dt/synapse.svg)](https://hex.pm/packages/synapse)\n[![Elixir](https://img.shields.io/badge/elixir-~%3E%201.15-purple.svg)](https://elixir-lang.org/)\n[![License](https://img.shields.io/hexpm/l/synapse.svg)](LICENSE)\n\nVersion: v0.1.1 (2025-11-29)\n\nSynapse is a headless, declarative multi‑agent orchestration framework. It provides a domain‑agnostic signal bus, workflow engine with Postgres persistence, and a configurable agent runtime for building domain-specific multi‑agent systems. A code review domain ships as a reference implementation; register it or build your own domains using the signal registry.\n\nHighlights\n\n- Domain‑agnostic signal registry with runtime topic registration\n- Declarative orchestrator runtime (no GenServer boilerplate)\n- Signal roles for orchestrator agents and configurable actions\n- Workflow engine with persistence and audit trail (`workflow_executions`)\n- Jido plan compiler/runner for turning plans into workflow specs\n- LineageIR spans/artifacts plus RunIndex and Work job emissions\n- LLM gateway powered by Altar.AI (optional) with ReqLLM fallback\n- Telemetry throughout (router, workflows, LLM requests)\n\n## Quick Start\n\n1. **Install dependencies**\n\n   ```bash\n   mix setup\n   ```\n\n2. **Create and migrate the database**\n\n   By default, dev connects to `postgres://postgres:postgres@localhost:5432/synapse_dev`. Override via `POSTGRES_*` env vars (see config/dev.exs).\n\n   ```bash\n   mix ecto.create\n   mix ecto.migrate\n   ```\n\n3. **Run the Stage 2 demo (optional sanity check)**\n\n   ```bash\n   mix run examples/stage2_demo.exs\n   ```\n\n   This boots the runtime, publishes a review request, and prints the resulting summary so you can see the declarative orchestrator in action.\n\n4. **Run the Plan compiler demo (optional)**\n\n   ```bash\n   mix run examples/plan_compiler_demo.exs\n   ```\n\n   This compiles a Jido plan into a workflow spec and executes it through the engine.\n\n5. **Start the runtime for development**\n\n   ```bash\n   iex -S mix\n   ```\n\n   This boots `Synapse.Runtime`, the signal router, the orchestrator runtime (reading `priv/orchestrator_agents.exs`), and the workflow engine with Postgres persistence. The application is OTP‑only — no Phoenix endpoint is required.\n\n6. **Run the Altar.AI integration example (optional)**\n\n   ```bash\n   mix run examples/altar_ai_integration.exs\n   ```\n\n## Submit a Review Request\n\nWith `Synapse.Domains.CodeReview` registered, publish a `:review_request` signal from CI, a script, or an iex session:\n\n```elixir\n{:ok, _signal} =\n  Synapse.SignalRouter.publish(\n    Synapse.SignalRouter,\n    :review_request,\n    %{\n      review_id: \"PR-12345\",\n      diff: git_diff,\n      files_changed: 12,\n      labels: [\"security\"],\n      intent: \"feature\",\n      metadata: %{repo: \"org/app\", author: \"alice\", files: touched_paths}\n    },\n    source: \"/ci/github\"\n  )\n```\n\nThe coordinator workflow classifies the request, spawns security/performance specialists as needed, and persists every step to `workflow_executions`.\n\n## Custom Domains\n\nSynapse is domain-agnostic. Define your own signals in config:\n\n```elixir\n# config/config.exs\nconfig :synapse, Synapse.Signal.Registry,\n  topics: [\n    ticket_created: [\n      type: \"support.ticket.created\",\n      schema: [\n        ticket_id: [type: :string, required: true],\n        customer_id: [type: :string, required: true],\n        subject: [type: :string, required: true],\n        priority: [type: {:in, [:low, :medium, :high]}, default: :medium]\n      ]\n    ]\n  ]\n```\n\nOr register at runtime:\n\n```elixir\nSynapse.Signal.register_topic(:my_event,\n  type: \"my.domain.event\",\n  schema: [id: [type: :string, required: true]]\n)\n```\n\nSee [docs/guides/custom-domains.md](docs/guides/custom-domains.md) for a full walkthrough.\n\n## Code Review Domain\n\nTo enable the built-in code review domain (security/performance specialists, review signals), register it via config:\n\n```elixir\n# config/config.exs\nconfig :synapse, :domains, [Synapse.Domains.CodeReview]\n```\n\nYou can also call `Synapse.Domains.CodeReview.register/0` during application startup if you prefer manual control.\n\n## Agent Configuration\n\nOrchestrator agents can specify signal roles for custom domains:\n\n```elixir\n%{\n  id: :my_coordinator,\n  type: :orchestrator,\n  signals: %{\n    subscribes: [:ticket_created, :ticket_analyzed],\n    emits: [:ticket_resolved],\n    roles: %{\n      request: :ticket_created,\n      result: :ticket_analyzed,\n      summary: :ticket_resolved\n    }\n  },\n  orchestration: %{\n    classify_fn: \u0026MyApp.classify/1,\n    spawn_specialists: [:analyzer, :responder],\n    aggregation_fn: \u0026MyApp.aggregate/2\n  }\n}\n```\n\n## Consume Results\n\nSubscribe to summaries if you want push-style notifications:\n\n```elixir\n{:ok, _sub_id} = Synapse.SignalRouter.subscribe(Synapse.SignalRouter, :review_summary)\n\nreceive do\n  {:signal, %{type: \"review.summary\", data: summary}} -\u003e\n    IO.inspect(summary, label: \"Review complete\")\nend\n```\n\nOr query Postgres for historical/auditable data:\n\n```elixir\nSynapse.Workflow.Execution\n|\u003e where(review_id: \"PR-12345\")\n|\u003e Synapse.Repo.one!()\n```\n\nEach execution record includes the workflow name, step-by-step audit trail, accumulated results, and the final status, so you can drive dashboards or rerun failed work.\n\n## AI Integration (Altar.AI)\n\nSynapse can delegate LLM operations to `altar_ai` via the compatibility layer:\n\n```elixir\nalias Altar.AI.Integrations.Synapse, as: LLM\n\n{:ok, response} = LLM.chat_completion(%{prompt: \"Hello\"}, profile: :openai)\n```\n\n`Synapse.ReqLLM` remains available but is deprecated and will be removed in a\nfuture release.\n\n## Orchestrator \u0026 Specialists\n\nSpecialists and the coordinator are declared in `priv/orchestrator_agents.exs` and are reconciled and run by `Synapse.Orchestrator.Runtime`. Update this file to add or tune agents — no GenServer code needed.\n\nExample snippet:\n\n```elixir\n%{\n  id: :coordinator,\n  type: :orchestrator,\n  actions: [Synapse.Domains.CodeReview.Actions.ClassifyChange],\n  orchestration: %{\n    classify_fn: \u0026MyStrategies.classify/1,\n    spawn_specialists: [:security_specialist, :performance_specialist],\n    aggregation_fn: \u0026MyStrategies.aggregate/2,\n    negotiate_fn: \u0026MyStrategies.resolve_conflicts/2\n  },\n  signals: %{\n    subscribes: [:review_request, :review_result],\n    emits: [:review_summary],\n    roles: %{\n      request: :review_request,\n      result: :review_result,\n      summary: :review_summary\n    }\n  },\n  state_schema: [review_count: [type: :non_neg_integer, default: 0]]\n}\n```\n\nOn boot, the orchestrator runtime validates configs, spawns any missing agents, and monitors process health. Update the file and trigger a reload to reconcile changes.\n\n## Declarative Workflow Engine\n\nThe workflow engine executes declarative specs (steps + dependencies) with retries, compensation, and telemetry. It powers specialist runs and the coordinator paths while giving you a uniform audit trail and optional Postgres persistence.\n\nKey pieces\n\n- Spec: `Synapse.Workflow.Spec` with `Step` and `Output` helpers\n- Engine: `Synapse.Workflow.Engine.execute/2` runs the spec and emits telemetry\n- Persistence (optional): snapshots to `workflow_executions` via `Synapse.Workflow.Persistence`\n\nMinimal example\n\n```elixir\nalias Synapse.Workflow.{Spec, Engine}\nalias Synapse.Workflow.Spec.Step\n\nspec =\n  Spec.new(\n    name: :example_workflow,\n    description: \"Analyze and generate critique with retries\",\n    metadata: %{version: 1},\n    steps: [\n      Step.new(\n        id: :fetch_context,\n        action: MyApp.Actions.FetchContext,\n        # env = %{input, results, context, step, workflow}\n        params: fn env -\u003e %{id: env.input.review_id} end\n      ),\n      Step.new(\n        id: :analyze,\n        action: Synapse.Actions.CriticReview,\n        requires: [:fetch_context],\n        retry: [max_attempts: 3, backoff: 200],\n        on_error: :continue,\n        params: fn env -\u003e %{diff: env.input.diff, metadata: env.results.fetch_context} end\n      ),\n      Step.new(\n        id: :generate_critique,\n        action: Synapse.Actions.GenerateCritique,\n        requires: [:analyze],\n        params: fn env -\u003e\n          review = env.results.analyze\n          %{\n            prompt: \"Summarize issues\",\n            messages: [%{role: \"user\", content: Enum.join(review.issues || [], \", \")}],\n            profile: :openai\n          }\n        end\n      )\n    ],\n    outputs: [\n      Spec.output(:review, from: :analyze),\n      Spec.output(:critique, from: :generate_critique, path: [:content])\n    ]\n  )\n\ninput = %{review_id: \"PR-42\", diff: \"...\"}\nctx = %{request_id: \"req_abc123\"} # required when persistence is enabled\n\ncase Engine.execute(spec, input: input, context: ctx) do\n  {:ok, %{results: _results, outputs: outputs, audit_trail: audit}} -\u003e\n    IO.inspect(outputs.critique, label: \"Critique\")\n    IO.inspect(audit.steps, label: \"Audit trail\")\n\n  {:error, %{failed_step: step, error: error, audit_trail: audit}} -\u003e\n    IO.inspect({step, error}, label: \"Workflow failed\")\n    IO.inspect(audit.steps, label: \"Audit trail\")\nend\n```\n\nParameters and env\n\n- Step params may be a map/keyword, or a function `fn env -\u003e ... end` where `env` includes `:input`, `:results`, `:context`, `:step`, and `:workflow`.\n- Steps support `requires: [:other_step]`, `retry: [max_attempts:, backoff:]`, and `on_error: :halt | :continue`.\n- Outputs map step results to the final payload; `path` lets you pick nested fields; `transform` is available for custom shaping.\n\nPersistence\n\n- Dev config enables persistence by default: see `config/config.exs` for `config :synapse, Synapse.Workflow.Engine, persistence: {Synapse.Workflow.Persistence.Postgres, []}`.\n- When persistence is enabled, you must provide a `:request_id` in `context`; the engine will snapshot before/after steps to `workflow_executions`.\n- You can override per call: `Engine.execute(spec, input: ..., context: ..., persistence: nil)`.\n\nTelemetry\n\n- Emits `[:synapse, :workflow, :step, :start|:stop|:exception]` with metadata like `:workflow`, `:workflow_step`, `:workflow_attempt`.\n- Example handler:\n\n```elixir\n:telemetry.attach(\n  \"wf-logger\",\n  [[:synapse, :workflow, :step, :stop]],\n  fn _evt, m, meta, _ -\u003e\n    require Logger\n    Logger.info(\"step done\",\n      workflow: meta.workflow,\n      step: meta.workflow_step,\n      attempt: meta.workflow_attempt,\n      duration_us: m.duration_us\n    )\n  end,\n  nil\n)\n```\n\nError and result shapes\n\n- Success: `{:ok, %{results: map(), outputs: map(), audit_trail: map()}}`\n- Failure: `{:error, %{failed_step: atom(), error: term(), attempts: pos_integer(), results: map(), audit_trail: map()}}`\n\nFurther reading\n\n- Cookbook: `docs_new/workflows/engine.md`\n- ADR: `docs_new/adr/0004-declarative-workflow-engine.md`\n\n## Plan Compiler (Jido.Plan)\n\nSynapse can compile `Jido.Plan` DAGs into workflow specs. Use `Synapse.PlanRunner`\nto compile and execute in one step, or `Synapse.PlanCompiler` if you need to\ninspect/modify the spec before running.\n\n```elixir\nalias Jido.Plan\nalias Synapse.PlanRunner\nalias Synapse.Workflow.Spec\n\nplan =\n  Plan.new(context: %{tenant_id: \"acme\"})\n  |\u003e Plan.add(:fetch, {MyApp.Actions.Fetch, %{value: 2}})\n  |\u003e Plan.add(:double, {MyApp.Actions.Double, %{value: 4}}, depends_on: :fetch)\n\n{:ok, exec} =\n  PlanRunner.run(plan,\n    name: :demo_plan,\n    outputs: [Spec.output(:result, from: :double, path: [:value])],\n    input: %{},\n    context: %{request_id: \"req_plan_demo\"}\n  )\n```\n\nPlan compilation maps `depends_on` -\u003e `requires`, applies instruction options\n(`max_retries`, `backoff`, `timeout`), and merges plan/instruction context into\neach workflow step.\n\n## LLM Providers (Req)\n\nSynapse uses `Req` for HTTP and provides a multi‑provider LLM gateway. Configure at runtime via environment:\n\n```bash\nexport OPENAI_API_KEY=sk-...\n# or\nexport GEMINI_API_KEY=ya29....\n```\n\nConfiguration is assembled in `config/runtime.exs`. Profiles support timeouts, retries, and provider‑specific options.\n\nExample usage:\n\n```elixir\n{:ok, resp} =\n  Synapse.ReqLLM.chat_completion(%{\n    messages: [%{role: \"user\", content: \"Summarize the following diff...\"}],\n    temperature: 0.2\n  }, profile: :openai)\n\nresp.content     # normalized string content\nresp.metadata    # token usage, finish_reason, provider-specific details\n```\n\nSee: `lib/synapse/req_llm.ex`, `lib/synapse/providers/*`, and `docs_new/20251029/implementation/LLM_INTEGRATION.md`.\n\n## Persistence\n\n- Adapter: `Synapse.Workflow.Persistence.Postgres`\n- Schema: `workflow_executions` (created by migration at `priv/repo/migrations/*_create_workflow_executions.exs`)\n- Test env disables persistence by default (`config/test.exs`)\n\nCommon tasks:\n\n```bash\nmix ecto.create\nmix ecto.migrate\nmix ecto.rollback\n```\n\nDatabase configuration for dev can be overridden with `POSTGRES_HOST`, `POSTGRES_DB`, `POSTGRES_USER`, `POSTGRES_PASSWORD`, `POSTGRES_PORT`, `POSTGRES_POOL_SIZE`.\n\n## Telemetry\n\n- Signals: `[:synapse, :signal_router, :publish|:deliver]`\n- LLM: `[:synapse, :llm, :request, :start|:stop|:exception]`\n- Workflows/Orchestrator: see `docs_new/20251028/remediation/telemetry_documentation.md`\n\nAttach your own handlers using `:telemetry.attach/4`.\n\n## Lineage, RunIndex, and Work Events\n\nWorkflow execution emits LineageIR trace/span/artifact events, RunIndex run/step\nwrites, and NSAI Work job lifecycle events. Configure adapters globally:\n\n```elixir\nconfig :synapse,\n  lineage_ir: true,\n  run_index_adapter: Synapse.RunIndex.Adapters.Ecto,\n  run_index_repo: Synapse.Repo,\n  work_adapter: Synapse.WorkEmitter.Adapters.Telemetry\n\nconfig :lineage_ir,\n  sink_adapter: LineageIR.Sink.Adapters.Ecto,\n  ecto_repo: Synapse.Repo\n```\n\nYou can override per call via `Engine.execute/2` options:\n`lineage_ir`, `lineage_opts`, `run_index_adapter`, `run_index_opts`,\n`work_adapter`, and `work_opts`.\n\n## Tests\n\nRun the full suite with:\n\n```bash\nmix test\n```\n\nDialyzer and other pre-commit checks are available via `mix precommit`.\n\n## Roadmap \u0026 Docs\n\n- Roadmap: `ROADMAP.md`\n- Orchestrator design and reference: `docs_new/20251028/synapse_orchestrator/README.md`\n- Multi‑agent framework docs: `docs_new/20251028/multi_agent_framework/README.md`\n- Workflow engine and persistence: `docs_new/workflows/engine.md` and ADRs in `docs_new/adr/`\n- Post‑Phoenix direction: `docs_new/20251109/README.md`\n- Custom domains guide: `docs/guides/custom-domains.md`\n- Plan compiler guide: `docs/guides/plan-compiler.md`\n- Migration guide: `docs/guides/migration-0.1.1.md`\n\n## Changelog\n\nSee `CHANGELOG.md`.\n\n## Tags\n\nelixir • otp • beam • erlang-vm • concurrency • fault-tolerance • supervision • jido • req • multi-agent • agent-orchestration • multi-agent-systems • orchestrator • workflows • llm • openai • gemini • postgres • telemetry • ai\n\n## License\n\nLicensed under MIT. See [LICENSE](LICENSE).\n","funding_links":[],"categories":["Generative AI"],"sub_categories":["Agent Frameworks"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnshkrdotcom%2Fsynapse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnshkrdotcom%2Fsynapse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnshkrdotcom%2Fsynapse/lists"}