Skip to main content

A modular framework for building generative AI wrapper components, including generative tools, pipelines, and agents.

Project description

📘 Forgen API - For Generative AI Interfacing

📘 Forgen - Agent Package Documentation

Overview

The forgen.agent package provides a modular and structured way to build AI-driven agents by defining GenerativeNodes, connecting them into Agents, and constructing tools that interact within this system.

This package includes:

  • AgentBuilder - Constructs agents by chaining different phases together.
  • ToolBuilder - Creates tools with input/output processing.
  • Agent - Represents a sequence of GenerativeNode objects.
  • AgentPipeline - Manages execution flow and dependencies.
  • Tool - A modular processing unit akin to an agent.

📌 Modules

1️⃣ builder.py - Agent and Tool Construction

This module provides AgentBuilder and ToolBuilder classes to construct AI-driven agent architectures.

🏗️ Class: AgentBuilder

Builds an agent by defining a sequence of GenerativeNodes, where each node consists of:

  • InputPhase (Preprocessing)
  • GenerationPhase (AI/Processing)
  • OutputPhase (Postprocessing)
🔹 __init__(agent_name: str, openai_client=None)

Initializes the agent builder.

  • agent_name (str): Name of the agent.
  • openai_client (Optional): OpenAI client for text generation (if applicable).
🔹 set_global_input_schema(input_schema: dict)

Sets the input schema for the entire agent.

🔹 set_global_output_schema(output_schema: dict)

Sets the output schema for the entire agent.

🔹 add_node(...)

Adds a processing node to the agent.

  • generation_function (callable): Function to generate output.
  • code_input (callable, optional): Function for input preprocessing.
  • code_output (callable, optional): Function for output postprocessing.
  • input_data (dict, optional): Initial input data.
  • generation_input_schema (dict, optional): Schema for generation input.
  • generation_output_schema (dict, optional): Schema for generation output.
  • max_tries (int, optional): Retry attempts for generation.
🔹 build() -> Agent

Constructs the agent and returns an instance of Agent.


🛠️ Class: ToolBuilder

Builds a Tool, which is a modular processing unit for the agent.

🔹 __init__(tool_name: str = None, input_schema: dict = None, output_schema: dict = None)

Initializes a tool with optional schemas.

🔹 set_tool(...)

Defines a tool's core behavior.

  • tool_fn (callable): Function to be executed.
  • input_schema (dict): Expected input structure.
  • output_schema (dict): Expected output structure.
  • preprocessing (callable, optional): Function for preprocessing.
  • postprocessing (callable, optional): Function for postprocessing.
  • forced_interface (bool, optional): Enforce schema validation.
🔹 build() -> Tool

Constructs and returns a Tool.


2️⃣ agent.py - Core Agent Execution

🤖 Class: Agent

An Agent is a collection of GenerativeNodes that process data sequentially.

🔹 __init__(agent_name: str, agent_nodes: List[GenerativeNode])

Initializes an agent with:

  • agent_name (str): Name of the agent.
  • agent_nodes (List[GenerativeNode]): Ordered nodes to be executed.
🔹 execute(input_data: dict = None) -> list

Executes the agent sequentially, processing data through all nodes.


3️⃣ node.py - Node Definition

Defines an GenerativeNode, which consists of:

  • InputPhase
  • GenerationPhase
  • OutputPhase

Each node processes input → generates output → formats output.


4️⃣ tool.py - Tool Execution and Processing

🛠 Class: Tool

A Tool is a modular processing unit that follows the same structure as an agent but operates as a single component.

🔹 __init__(...)

Initializes a Tool with input, operation, and output phases.

  • input (InputPhase): Preprocessing step.
  • operation (OperativePhase): Core function execution.
  • output (OutputPhase): Postprocessing step.
  • input_schema (dict): Schema for input validation.
  • output_schema (dict): Schema for output validation.
  • forced_interface (bool): Whether to allow schema-based mapping.
🔹 execute(input_data: dict) -> dict

Processes data through the input, operation, and output phases.


📌 Class: InputPhase

Handles input validation and preprocessing.

🔹 process_input() -> dict

Validates input and applies preprocessing.


📌 Class: OperativePhase

Handles the main function execution.

🔹 use_tool() -> dict

Executes the tool's primary function and returns output.


📌 Class: OutputPhase

Handles output validation and postprocessing.

🔹 format_output() -> dict

Applies postprocessing and validates output.


5️⃣ pipeline/agent_pipeline.py - Pipeline Execution

🔄 Class: AgentPipeline

Manages dependencies and execution order of GenerativeNodes.

🔹 __init__(pipeline_object: dict)

Initializes a pipeline with an agent definition.

🔹 execute(input_data: dict)

Runs the pipeline by resolving dependencies and executing nodes.


6️⃣ pipeline/builder.py - Pipeline Construction

🏗 Class: PipelineBuilder

Builds a Pipeline, which connects multiple GenerativeNodes in a structured sequence.

🔹 set_master_input(master_input: dict)

Defines the initial input data for the pipeline.

🔹 add_item(item: PipelineItem)

Adds an item (processing unit) to the pipeline.

🔹 add_engine_tuple(source: str, target: str)

Defines a processing flow between pipeline components.

🔹 build() -> dict

Constructs and returns a pipeline definition.


7️⃣ pipeline/item.py - Pipeline Components

🔹 Class: BaseModule

Abstract base class defining a pipeline component interface.

Abstract Methods:
  • input_schema
  • output_schema
  • execute()

🔹 Class: PipelineItem

Encapsulates an agent or tool as a component in a pipeline.

🔹 __init__(id: str, agent_or_tool: BaseModule, ...)

Initializes a PipelineItem with:

  • id (str): Unique identifier.
  • agent_or_tool (BaseModule): An agent or tool to execute.
  • cust_input_schema (dict, optional): Custom input schema.
  • cust_output_schema (dict, optional): Custom output schema.
🔹 execute(input_data: dict = None) -> dict

Executes the agent/tool with the given input.


🎯 Usage Example: Creating an Agent

from forgen.tool.builder import AgentBuilder

# Initialize the AgentBuilder
builder = AgentBuilder(agent_name="TextProcessor")

# Define global schemas
builder.set_input_schema({"text": str})
builder.set_global_output_schema({"summary": str})


# Define generation function
def summarize_text(input_data):
    text = input_data["text"]
    return {"summary": text[:100]}  # Simple truncation


# Add processing node
builder.create_and_add_gen_node(generative_function=summarize_text)

# Build the agent
agent = builder.build()

# Execute the agent
result = agent.execute({"text": "This is a long article that needs summarization."})
print(result)  # {'summary': 'This is a long article that needs summarization.'}

This documentation provides a structured reference for developers working with the forgen.agent package. Let me know if you need any modifications! 🚀

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

forgen-0.1.4.tar.gz (104.1 kB view details)

Uploaded Source

Built Distribution

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

forgen-0.1.4-py3-none-any.whl (142.2 kB view details)

Uploaded Python 3

File details

Details for the file forgen-0.1.4.tar.gz.

File metadata

  • Download URL: forgen-0.1.4.tar.gz
  • Upload date:
  • Size: 104.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for forgen-0.1.4.tar.gz
Algorithm Hash digest
SHA256 e2ccbd7550eb8c0fe11024eb7b7c3a86803bb0f0e30c3c42fce1bbfbba2b94ee
MD5 965aa78df7d8c94c79370fcd52c02de6
BLAKE2b-256 e7e5ee9df38383602789f08858a0795aa17d79f5ab458cc685052050696fecb8

See more details on using hashes here.

Provenance

The following attestation bundles were made for forgen-0.1.4.tar.gz:

Publisher: workflow.yml on ForGen-AI/forgen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file forgen-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: forgen-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 142.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for forgen-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 4c7fe0f7d313844176680209793aa5fd656e33cc7da9afc08434cb627d056deb
MD5 3b4780cacb25718a1a79775f8da492b3
BLAKE2b-256 f5523afea1f64fbe9df080f8023b7902d7c538013c450726cf2d6bc0ff938c2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for forgen-0.1.4-py3-none-any.whl:

Publisher: workflow.yml on ForGen-AI/forgen

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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