from splinter.coordination import ActionEligibilityelig = ActionEligibility()# Only researcher can act initiallyelig.set_eligible("researcher")# Check who can actelig.can_act("researcher") # Trueelig.can_act("writer") # False# Transfer eligibilityelig.transfer("researcher", "writer")elig.can_act("writer") # Trueelig.can_act("researcher") # False
from splinter.coordination import EligibilityMode# Single: Only one agent at a time (default)elig = ActionEligibility(mode=EligibilityMode.SINGLE)# Multiple: Multiple agents can be eligibleelig = ActionEligibility(mode=EligibilityMode.MULTIPLE)elig.set_eligible("researcher")elig.set_eligible("writer") # Both can act# Turn-based: Rotate through agentselig = ActionEligibility(mode=EligibilityMode.TURN_BASED)elig.set_turn_order(["researcher", "writer", "reviewer"])
# Set rules for eligibilityelig.add_rule( agent="writer", requires=["researcher"], # Writer can only act after researcher)elig.add_rule( agent="reviewer", requires=["researcher", "writer"], # After both)# Eligibility auto-updates based on ruleselig.mark_complete("researcher")# Now writer is eligible
# Who is currently eligible?eligible = elig.get_eligible_agents() # ["researcher"]# Why isn't writer eligible?reason = elig.why_not_eligible("writer")# "Waiting for researcher to complete"# Get all statusesstatuses = elig.get_all_statuses()# {"researcher": "eligible", "writer": "waiting", "reviewer": "waiting"}
def on_eligible(agent_id): print(f"{agent_id} is now eligible to act")def on_ineligible(agent_id, reason): print(f"{agent_id} no longer eligible: {reason}")elig.on_eligible(on_eligible)elig.on_ineligible(on_ineligible)
workflow = Workflow(workflow_id="pipeline")elig = ActionEligibility()workflow.set_eligibility(elig)# Workflow uses eligibility to decide which agent runs next