Skip to main content

Route inbound context to agent + session scope via fnmatch binding rules

Project description

nodus-router

Route inbound context to agent + session scope via fnmatch binding rules.

Maps channel/peer/thread patterns to agent IDs with priority-ordered binding rules. Resolves inbound messages to a RouteMatch containing the agent ID, a SessionKey, and the matched binding. No required external dependencies — pure stdlib with optional nodus-session integration.

Status: v0.1.0 — prepared, not yet published.


Install

pip install nodus-router

# With nodus-session SessionKey integration:
pip install "nodus-router[session]"

What it provides

Component Purpose
InboundContext Inbound message context: channel, peer, thread, roles, metadata
RouteBinding fnmatch pattern → agent_id mapping with priority
RoutingTable Thread-safe ordered list of RouteBinding objects
RouteResolver Evaluates table, returns RouteMatch (with default fallback)
RouteMatch Resolved agent_id, SessionKey, and matched binding

Quick start

from nodus_router import InboundContext, RouteBinding, RoutingTable, RouteResolver

table = RoutingTable()
table.add(RouteBinding(
    channel_pattern="slack",
    peer_pattern="*",
    agent_id="general-agent",
    priority=10,
))
table.add(RouteBinding(
    channel_pattern="slack",
    peer_pattern="U123*",
    agent_id="vip-agent",
    priority=20,   # higher priority wins
))

resolver = RouteResolver(table, default_agent_id="fallback-agent")

ctx = InboundContext(channel_id="slack", peer_id="U123456", thread_id=None)
match = resolver.resolve(ctx)

print(match.agent_id)        # "vip-agent"
print(match.session_key)     # SessionKey(agent_id="vip-agent", channel="slack", ...)
print(match.binding)         # the matched RouteBinding

InboundContext

from nodus_router import InboundContext

ctx = InboundContext(
    channel_id="slack",
    peer_id="U123456",
    thread_id="T789",    # optional
    roles=["user"],      # optional list of role strings
    metadata={},         # optional extra data
)

RouteBinding

from nodus_router import RouteBinding

binding = RouteBinding(
    channel_pattern="slack",   # fnmatch — "*" matches any channel
    peer_pattern="U123*",      # fnmatch — matches any peer starting with U123
    agent_id="vip-agent",
    priority=20,               # higher priority evaluated first
)

Patterns use fnmatch* matches any sequence, ? matches one character.


RoutingTable

from nodus_router import RoutingTable

table = RoutingTable()
table.add(binding)
table.remove(agent_id="vip-agent")
table.list_bindings()          # list sorted by priority descending
len(table)

Thread-safe — safe to add/remove from multiple threads.


RouteResolver

from nodus_router import RouteResolver

resolver = RouteResolver(
    table,
    default_agent_id="fallback-agent",  # used when no binding matches
)

match = resolver.resolve(ctx)
# match.agent_id    — resolved agent
# match.session_key — SessionKey (from nodus-session if installed, else fallback)
# match.binding     — matched RouteBinding | None (None = default fallback)

SessionKey integration

When nodus-session is installed, RouteMatch.session_key is a real SessionKey from that package. Without it, a lightweight fallback dataclass with the same fields is used — no functionality is lost.

pip install "nodus-router[session]"

Design

  • No required dependencies. fnmatch and threading are stdlib. nodus-session is optional — a fallback SessionKey is used when absent.
  • Priority ordering. Bindings are sorted by priority descending; first match wins.
  • Thread-safe. RoutingTable uses threading.Lock.

Development

pip install -e ".[dev]"
pytest tests/ -q

License

MIT — see LICENSE.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nodus_router-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nodus_router-0.1.0-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file nodus_router-0.1.0.tar.gz.

File metadata

  • Download URL: nodus_router-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for nodus_router-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fe5374210a2ecbe7afe0fafc41e578de36e778e82ae1261e784e20204eae5772
MD5 20ffaec0b109b6425449453eda27af11
BLAKE2b-256 5cf77e28962cf3bb094cdbef0cab5158273c5d88222c20931cad4e9c6642b1de

See more details on using hashes here.

File details

Details for the file nodus_router-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nodus_router-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for nodus_router-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 895a1bcebc264ea2551796417fa430935c7755dc128c1eec6c5143c275690acc
MD5 aadb9af9fd86dae3fcd464a5dd7ee030
BLAKE2b-256 1bf0c09255e60317ee8cc0451e79f84085022cea2dd0f0653bd6ba34e7a94ca2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page