Peeps and Workchains

Combining Peeps and Workchains

The true power of Peeps AI emerges when Peeps (autonomous teams of AI agents) and Workchains (event-driven workflows) are combined to create scalable, adaptive, and intelligent systems. By leveraging the strengths of both, developers can orchestrate workflows that balance agent autonomy with programmatic control, making it possible to solve complex real-world problems efficiently.

This section explores the seamless integration of Peeps and Workchains, their unique synergy, and how they work together to achieve unparalleled levels of flexibility and precision.


Why Combine Peeps and Workchains?

Peeps and Workchains serve complementary roles within Peeps AI:

  • Peeps bring autonomy and collaboration to the table, enabling agents to dynamically allocate tasks, validate results, and adapt to evolving challenges.

  • Workchains provide the structure and control needed to manage workflows, ensuring predictability, error resilience, and integration with external systems.

When combined, Peeps handle the "how" of problem-solving (e.g., autonomous decisions and task execution), while Workchains define the "what" and "when" (e.g., workflow steps, dependencies, and triggers).


How Peeps and Workchains Work Together

Task Orchestration

  • Workchains delegate tasks to Peeps, which handle them autonomously using their role-based expertise. For example:

    • A Workchain might define a step to "analyze market trends."

    • The associated Peep will assign this task to the appropriate agent(s) based on their roles, such as a "Data Analyst" or "Market Researcher."

Dynamic Adaptation

  • Peeps use their autonomy to make decisions within a task, while Workchains enforce overarching rules and transitions. If a Peep encounters incomplete or ambiguous data, it can request clarification or additional resources without disrupting the workflow.

Stateful Collaboration

  • The Workchain manages state across tasks and agents, ensuring that intermediate outputs from Peeps are stored, validated, and passed seamlessly to subsequent steps.

Feedback Loops

  • Outputs generated by Peeps are analyzed by the Workchain, which can loop back to earlier steps if results fail to meet predefined thresholds or conditions.


Key Features of the Integration

Role-Based Autonomy with Programmatic Control

  • Peeps allow agents to autonomously delegate and collaborate on tasks.

  • Workchains enforce high-level coordination, ensuring that workflows align with business logic and external requirements.

Example:

# agents.yaml
data_analyst:
  role: "Market Analyst"
  goal: "Extract actionable insights from market data."

validator:
  role: "Quality Validator"
  goal: "Ensure the accuracy and relevance of insights."

# tasks.yaml
analyze_market:
  description: "Perform a market analysis using historical and current data."
  agent: data_analyst

validate_results:
  description: "Review analysis results for accuracy and completeness."
  agent: validator

The Workchain ensures the workflow proceeds logically, while the Peep autonomously manages the delegation of "analyze_market" and "validate_results."


Conditional Execution with Adaptive Decisions

  • Workchains handle high-level branching (e.g., "if analysis confidence > 80%, proceed to reporting"), while Peeps decide internally how best to fulfill each task.

Example:

class MarketAnalysisWorkflow(Flow):
    @start()
    def initiate_analysis(self):
        return {"sector": "technology"}

    @listen(initiate_analysis)
    def analyze(self, inputs):
        # Delegate analysis to a Peep
        return Peeps(
            agents=["data_analyst", "validator"],
            tasks=["analyze_market", "validate_results"],
            process=Process.sequential
        ).kickoff(inputs=inputs)

    @router(analyze)
    def evaluate_results(self, outputs):
        if outputs['confidence'] > 0.8:
            return "proceed_to_reporting"
        else:
            return "request_additional_data"

Multi-Agent Collaboration

  • Workchains coordinate multiple Peeps, enabling complex workflows where different agent teams contribute specialized expertise.

Example:

  • Peep 1: Researches and validates data.

  • Peep 2: Generates a report based on the validated data.

  • Peep 3: Reviews and formats the report for publication.

The Workchain ensures proper sequencing and integration between these teams.


Interoperability with External Systems

  • Workchains integrate Peeps into external environments, enabling actions like:

    • Retrieving real-time data via APIs.

    • Writing results to external databases.

    • Triggering notifications or actions in other applications.

Last updated