DocumentationAdvancedSystem Context

System Context

Understanding where the Ainalyn SDK fits in the overall system architecture.


Application Architecture

Application Architecture

SDK as a Compiler

The most important concept to understand: The SDK is a compiler, not a runtime.


Key Boundaries

What the SDK Does

ResponsibilityDescription
DefineProvides builders to define Agent structure
ValidateChecks definition correctness before submission
ExportProduces platform-compatible YAML format
CompileComplete workflow: validate → serialize → output

What the SDK Does NOT Do

NOT ResponsibilityWhy
Execute agentsPlatform Core handles execution
Call LLMsPlatform Core manages LLM interactions
Manage statePlatform Core handles runtime state
Handle I/OPlatform Core manages external integrations

The Compilation Analogy

Think of Ainalyn SDK like a programming language compiler:

┌─────────────────────────────────────────────────────────────────────┐
│                        Traditional Compiler                          │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│   Source Code (.py)  ──▶  Compiler  ──▶  Bytecode (.pyc)           │
│                                                                     │
│   The compiler doesn't run your program;                            │
│   it produces something that can be run later.                      │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────┐
│                          Ainalyn SDK                                 │
├─────────────────────────────────────────────────────────────────────┤
│                                                                     │
│   Python Builders  ──▶  SDK  ──▶  Agent Definition (YAML)          │
│                                                                     │
│   The SDK doesn't run your agent;                                   │
│   it produces a definition that Platform Core executes.             │
│                                                                     │
└─────────────────────────────────────────────────────────────────────┘

Data Flow Overview

Developer                    SDK                         Platform
────────                    ───                         ────────

  │                          │                             │
  │  1. Write Python code    │                             │
  │  using builders          │                             │
  │                          │                             │
  ├─────────────────────────▶│                             │
  │                          │                             │
  │                          │  2. Validate structure      │
  │                          │     Check references        │
  │                          │     Detect cycles           │
  │                          │                             │
  │                          │  3. Serialize to YAML       │
  │                          │                             │
  │◀─────────────────────────┤                             │
  │  4. Return YAML / errors │                             │
  │                          │                             │
  │                          │                             │
  ├──────────────────────────┼────────────────────────────▶│
  │  5. Submit YAML to platform                            │
  │                          │                             │
  │                          │                             │  6. Parse YAML
  │                          │                             │  7. Execute agent
  │                          │                             │  8. Call LLMs
  │                          │                             │  9. Return results
  │                          │                             │

Why This Separation?

Benefits of Compiler Pattern

  1. Offline Validation

    • Catch errors before deployment
    • No network calls needed for validation
    • Fast feedback loop for developers
  2. Platform Independence

    • SDK produces a standard format (YAML)
    • Platform can evolve independently
    • Multiple platforms could consume the same format
  3. Clear Responsibility

    • SDK: definition correctness
    • Platform: execution correctness
    • No confusion about where bugs originate
  4. Testability

    • Test definitions without running agents
    • Mock-free unit tests for SDK
    • Integration tests only at platform level

What Gets Compiled

The SDK compiles your Python builder calls into an Agent Definition:

Input (Python):

from ainalyn import AgentBuilder, WorkflowBuilder, NodeBuilder
 
agent = (
    AgentBuilder("customer-support")
    .version("1.0.0")
    .description("Handles customer inquiries")
    .add_workflow(
        WorkflowBuilder("handle-inquiry")
        .add_node(NodeBuilder("classify").type("llm").build())
        .add_node(NodeBuilder("respond").type("llm").build())
        .add_edge("classify", "respond")
        .build()
    )
    .build()
)

Output (YAML):

name: customer-support
version: 1.0.0
description: Handles customer inquiries
workflows:
  - name: handle-inquiry
    nodes:
      - id: classify
        type: llm
      - id: respond
        type: llm
    edges:
      - from: classify
        to: respond