Skip to content

feat: add capability-based task routing#3

Open
zakiscoding wants to merge 1 commit intojoshualamerton:mainfrom
zakiscoding:feat/capability-based-routing
Open

feat: add capability-based task routing#3
zakiscoding wants to merge 1 commit intojoshualamerton:mainfrom
zakiscoding:feat/capability-based-routing

Conversation

@zakiscoding
Copy link

Summary

Implements capability-based task routing in TaskMesh.

New classes

  • Task(name, required_capabilities) — task with optional capability requirements
  • Agent(name, capabilities) — agent with a defined capability set
  • TaskRouter.register_agent(agent) — register an agent
  • TaskRouter.claim_task() now matches tasks to agents by capability

How it works

claim_task() iterates the queue and returns the first task the agent is capable of handling (all required capabilities present). Falls back to FIFO for unregistered agents (backward compatible).

Example

router.register_agent(Agent('analysis_agent', capabilities=['data_analysis']))
router.submit_task(Task('analyze_market_data', required_capabilities=['data_analysis']))
router.submit_task(Task('generate_report', required_capabilities=['reporting']))

router.claim_task('analysis_agent')  # gets analyze_market_data (capability match)
router.claim_task('analysis_agent')  # returns None (can't handle reporting task)

Closes #1

Closes joshualamerton#1

Adds Task and Agent classes with capability metadata. TaskRouter now
matches tasks to agents by required capabilities - claim_task() iterates
the queue and returns the first task the agent can handle.

Falls back to FIFO for unregistered agents (backward compatible).
Copilot AI review requested due to automatic review settings March 12, 2026 17:01
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements capability-based task routing in TaskMesh by introducing first-class Task/Agent models and updating the router to match queued tasks to agents based on required capabilities.

Changes:

  • Added Task and Agent classes and agent registration to TaskRouter.
  • Updated TaskRouter.submit_task() to accept either a string task name or a Task object (with optional capability requirements).
  • Updated the demo to register agents and submit capability-scoped tasks.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
core/task_router.py Introduces Task/Agent and capability-aware claim_task() routing logic.
examples/demo.py Demonstrates registering agents with capabilities and claiming capability-matched tasks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +8 to +10
def __repr__(self):
caps = ", ".join(self.required_capabilities) if self.required_capabilities else "any"
return f"Task({self.name\!r}, requires={caps})"
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Task.__repr__ uses {self.name\!r} (and similar in Agent.__repr__), which is invalid f-string syntax and will raise a SyntaxError. Remove the backslash and use the standard repr conversion {self.name!r} so the module can import/run.

Copilot uses AI. Check for mistakes.
Comment on lines +24 to +25
def __repr__(self):
return f"Agent({self.name\!r}, capabilities={sorted(self.capabilities)})"
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agent.__repr__ uses {self.name\!r}, which is invalid f-string syntax and will raise a SyntaxError. Remove the backslash and use {self.name!r}.

Copilot uses AI. Check for mistakes.
Comment on lines +4 to +6
def __init__(self, name: str, required_capabilities: list[str] | None = None):
self.name = name
self.required_capabilities = required_capabilities or []
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

README advertises Python 3.9+, but these type hints use PEP 604 unions (list[str] | None), which require Python 3.10+. To keep 3.9 compatibility, switch to Optional[...] / Union[...] (or bump the documented minimum Python version).

Copilot uses AI. Check for mistakes.
self.tasks.append(task)

def claim_task(self, agent_name):
def claim_task(self, agent_name: str) -> dict | None:
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This return annotation uses dict | None, which requires Python 3.10+. If TaskMesh targets Python 3.9+ (per README), use Optional[dict[...]] (and import Optional from typing) or update the documented Python requirement.

Copilot uses AI. Check for mistakes.

Iterates through the task queue in order and returns the first task
whose required capabilities are all present in the agent's capability set.
Falls back to the first available task if the agent has no capabilities registered.
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Docstring says routing “falls back to the first available task if the agent has no capabilities registered,” but the implementation only falls back when the agent is not registered (agent is None). For registered agents with an empty capability set, the router will only match tasks with no required capabilities. Please update the docstring (or adjust logic) so behavior and docs align.

Suggested change
Falls back to the first available task if the agent has no capabilities registered.
Falls back to the first available task if the agent is not registered.

Copilot uses AI. Check for mistakes.
@zakiscoding
Copy link
Author

Hi @joshualamerton! This PR is ready for review and merge. It implements capability-based task routing with Task and Agent classes as requested in #1. Let me know if you'd like any changes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Capability-based task routing

2 participants