WayFlow

repository·main·Indexed 41 days ago

https://github.com/oracle/wayflow

A Python library for building AI-powered assistants using autonomous Agents and structured Flows. It serves as the reference runtime implementation for the Open Agent Spec and supports multiple LLM providers, including OCI Gen AI, OpenAI, Ollama, and vLLM.

Tokens
100.9K
Snippets
286
Records
483
Agent score
52%

What's inside WayFlow

  1. Overview of WayFlow How-to Guides

    main

    WayFlow provides a collection of goal-oriented, concrete guides designed to help you complete specific tasks when building AI assistants. These guides cover several key domains:

    • Building Assistants: Creating Agents, Flows, and multi-agent patterns (Hierarchical, Swarm, Manager-Workers).
    • Tools in Assistants: Equipping assistants with server-side, client-side, remote API, or Model Context Protocol (MCP) tools.
    • Configuration and State Management: Managing agent specs, serialization, plugins, tracing, and the event system.
    • Data in Assistants: Connecting to data stores, using embedding models, managing shared state via variables, and building RAG-powered assistants.
    • Assistant Testing and Evaluation: Evaluating both assistants and individual conversations.

    Each code example provided in the guides is self-contained and can be executed using WayFlow.

  2. Overview of WayFlow capabilities

    main

    WayFlow is a Python library for building AI-powered assistants using two primary patterns:

    1. Agents: Flexible, autonomous entities that use LLMs to drive interaction.
    2. Flows: Structured, predictable sequences of steps for specific tasks.

    Key features include:

    • Interoperability: Works with various LLM vendors.
    • Reusability: Supports composable components and a standard library of plan steps.
    • Openness: Serves as the reference runtime implementation for the Open Agent Spec.
  3. What is the Swarm agentic pattern?

    main

    The Swarm pattern is an agentic architecture inspired by swarm intelligence, where coordinated behavior emerges from many simple actors rather than a central controller. In this pattern, each agent is assigned a specific responsibility and can delegate tasks to other specialized agents.

    Key characteristics:

    • Reduced LLM Calls: Compared to a hierarchical multi-agent pattern, the Swarm pattern reduces the number of LLM calls because agents can hand off the conversation directly to a recipient, rather than requiring every intermediate agent to relay messages back and forth.
    • Handoff vs. Messaging:
      • Messaging: An agent sends a message to another agent to get information.
      • Handoff: An agent transfers the full user-agent conversation to another agent. When a handoff occurs, the recipient agent replaces the caller and communicates directly with the human user.

    Note: The Swarm pattern is currently in beta. It cannot yet be used within a Flow, and its API is not guaranteed to be stable.

  4. What is tool output streaming and how it works

    main

    Tool output streaming allows a tool to produce intermediate outputs while it is still running, rather than waiting for the entire execution to complete. This is useful for UIs to display partial results in near real time.

    Key Mechanics:

    • Chunk Events: When streaming is enabled, WayFlow emits ToolExecutionStreamingChunkReceivedEvent as the tool makes progress.
    • Final Result: The tool's final output is the last value produced (the completed tool result). Earlier values are treated as streamed chunks and are not considered the final result.
    • Implementation: To enable streaming, define the tool as an async generator (an async callable that uses yield instead of return).
  5. What is a Flow in WayFlow

    main

    A Flow is a type of assistant composed of individual Steps connected in a coherent sequence of actions. Unlike an Agent, which typically maintains chat history for multi-turn conversations, a Flow is a structured way to execute specific business processes by chaining discrete, often stateless, functional steps.

    Common step types include:

    • InputMessageStep: Gathers input from the user.
    • ToolExecutionStep: Runs a tool (like a Python function) to fetch or manipulate data.
    • PromptExecutionStep: Executes a prompt using an LLM, supporting data insertion from previous steps via Jinja templating.
    • OutputMessageStep: Displays information to the user.
  6. Understand the difference between Flows and Agents

    main

    WayFlow provides two primary types of AI-powered assistants, which can be composed to solve complex tasks:

    • Flows: Structured assistants that follow a pre-defined, prescriptive task completion process. They are composed of individual steps connected in a sequence and are ideal for business processes where control and predictability are required.
    • Agents: Conversational assistants that can autonomously plan, think, act, and execute tools. They are more flexible and can interact with users and other assistants to solve requests through conversational interfaces.

    Agents can be integrated into Flows using an AgentExecutionStep.

  7. Use Extended Components for Agent Spec Export

    main

    Extended components are standard Agent Spec components that have been augmented with additional fields. These are specifically designed to allow developers to export their WayFlow assistants to Agent Spec while retaining extra metadata or configuration.

    Available extended components include:

    • ExtendedAgent
    • ExtendedFlow
    • ExtendedToolNode
    • ExtendedLlmNode
    • ExtendedMapNode
  8. Style and tone for WayFlow documentation

    main

    Maintain a conversational yet formal tone by following these rules:

    • Voice: Use the second-person singular (you). Use we only when referring to the developers. Prefer active voice over passive voice (e.g., use We recommend instead of It is recommended).
    • Avoid Marketing Language: Do not use phrases like It’s simple or It’s easy.
    • Avoid Contractions: Do not use it’s, you’ll, or you’re.
    • Gender Neutrality: Avoid gender-specific pronouns (he, she, his, hers). Use neutral plural subjects like developers or users.
    • Word Choice: Avoid using the word get in a casual sense (e.g., use were included instead of got included).
  9. Implement branching logic based on user input

    main

    For advanced workflows, you can combine InputMessageStep with BranchingStep to create decision logic. For example, you can ask for confirmation (e.g., "y/n") and use a BranchingStep to route the flow to either a ToolExecutionStep or a different path based on that input.

    from wayflowcore import Flow, InputMessageStep, BranchingStep, ToolExecutionStep
    
    # Example of a flow that asks for confirmation before a tool call
    def create_complex_flow():
        flow = Flow()
        flow.add_step(InputMessageStep(message_template="Confirm action? (y/n)"))
        
        # Branch based on the user's response
        flow.add_step(BranchingStep(
            branching_map={
                "y": "tool_step",
                "n": "skip_step"
            }
        ))
        
        flow.add_step(ToolExecutionStep(name="my_tool"), name="tool_step")
        return flow
  10. Configure generation parameters using LlmGenerationConfig

    main

    Use the LlmGenerationConfig class to control Large Language Model (LLM) output behavior such as randomness, token limits, and stop sequences. This configuration can be applied globally when initializing an LLM or locally to override settings for a specific step in a flow.

    Supported arguments for LlmGenerationConfig include:

    • max_new_tokens: Maximum number of tokens to generate (excluding prompt tokens).
    • temperature: Controls output randomness.
    • top_p: Controls randomness via nucleus sampling.
    • stop: A list of stop words that signal the LLM to cease generation.
    • frequency_penalty: Controls the frequency of generated tokens.
    • top_logprobs: Requests token-level log probabilities (if supported by the provider).
    • extra_args: A dictionary of arbitrary, provider-specific parameters.
    from wayflowcore.llm.generation_config import LlmGenerationConfig
    
    config = LlmGenerationConfig(
        max_new_tokens=100,
        temperature=0.7,
        top_p=0.9,
        stop=["\n"],
        frequency_penalty=0.1,
        extra_args={"provider_specific_param": "value"}
    )