Skip to main content

Trajectory capture, reward signals, and learning infrastructure for agents.

Project description

Marlo Python SDK

The official Python SDK for Marlo - Continual learning platform.

Installation

pip install marlo-sdk

Quick Start

import marlo

# Initialize with your API key
marlo.init(api_key="your-api-key")

# Register your agent
marlo.agent(
    name="my-agent",
    system_prompt="You are a helpful assistant.",
    tools=[{"name": "search", "description": "Search the web"}],
)

# Track a task using context manager
with marlo.task(thread_id="thread-123", agent="my-agent") as task:
    task.input("Hello, how can you help?")

    # Your agent logic here...
    task.llm(
        model="gpt-5",
        usage={"input_tokens": 50, "output_tokens": 100},
        messages=[{"role": "user", "content": "Hello"}],
        response="I can help with many things!",
    )

    task.output("I can help with many things!")

# Shutdown before exit
marlo.shutdown()

Features

  • Task Tracking: Capture agent inputs, outputs, and interactions
  • LLM Call Recording: Track model usage, tokens, and responses
  • Tool Call Logging: Record tool invocations and results
  • Multi-Agent Support: Track parent-child agent relationships
  • Learnings Integration: Fetch and apply learnings from past interactions
  • Async-Safe: Background threading for non-blocking event sending

API Reference

Initialization

# Initialize the SDK
marlo.init(api_key="your-api-key")

# Shutdown and flush pending events
marlo.shutdown()

Agent Registration

marlo.agent(
    name: str,
    system_prompt: str,
    tools: list[dict],
    mcp: list[dict] | None = None,
    model_config: dict | None = None,
)
Parameter Description
name Unique identifier for your agent
system_prompt System prompt used by your agent
tools List of tool definitions [{"name": "...", "description": "..."}]
mcp Optional list of MCP server definitions
model_config Optional model configuration {"model": "gpt-4", ...}

Task Tracking

# Create a task context (use as context manager)
with marlo.task(thread_id: str, agent: str, thread_name: str | None = None) as task:
    # Record events within the task
    task.input(text)                    # User input
    task.output(text)                   # Agent response
    task.llm(model, usage, messages, response)  # LLM call
    task.tool(name, input, output, error)       # Tool call
    task.reasoning(text)                # Chain-of-thought
    task.error(message)                 # Mark task as failed

    # Fetch learnings
    learnings = task.get_learnings()

    # Create child task for multi-agent
    with task.child(agent="sub-agent") as child_task:
        child_task.input("Sub-task input")
        child_task.output("Sub-task output")

Task Methods

task.input(text: str)

Record the user's input message.

task.output(text: str)

Record the agent's final response.

task.llm(...)

Track an LLM call.

task.llm(
    model="gpt-4",
    usage={"input_tokens": 100, "output_tokens": 50},
    messages=[{"role": "user", "content": "Hello"}],
    response="Hi there!",
)

task.tool(...)

Track a tool call.

task.tool(
    name="search",
    input={"query": "weather"},
    output={"result": "sunny"},
    error=None,  # Optional error message
)

task.reasoning(text: str)

Record chain-of-thought or reasoning steps.

task.error(message: str)

Mark the task as failed with an error message.

task.get_learnings()

Fetch learnings from past interactions.

learnings = task.get_learnings()
if learnings:
    # Apply learnings to your agent
    pass

task.child(agent: str)

Create a child task for multi-agent workflows.

Complete Example

import marlo

# Initialize
marlo.init(api_key="mk_abc123")

# Register agent with tools
marlo.agent(
    name="support-bot",
    system_prompt="You are a customer support agent.",
    tools=[
        {"name": "lookup_order", "description": "Find order by ID"},
        {"name": "check_inventory", "description": "Check product stock"},
    ],
    model_config={"model": "gpt-4", "temperature": 0.7},
)


async def handle_message(thread_id: str, user_message: str) -> str:
    with marlo.task(thread_id=thread_id, agent="support-bot") as task:
        task.input(user_message)

        # Get learnings to improve responses
        learnings = task.get_learnings()

        # Build messages
        messages = [
            {"role": "system", "content": "You are a customer support agent."},
            {"role": "user", "content": user_message},
        ]

        # Call LLM
        response = await llm.chat(messages)
        answer = response.content

        # Track the LLM call
        task.llm(
            model="gpt-4",
            usage={
                "input_tokens": response.usage.prompt_tokens,
                "output_tokens": response.usage.completion_tokens,
            },
            messages=messages,
            response=answer,
        )

        # Track any tool calls
        if response.tool_calls:
            for tool_call in response.tool_calls:
                result = execute_tool(tool_call)
                task.tool(
                    name=tool_call.name,
                    input=tool_call.arguments,
                    output=result,
                )

        task.output(answer)
        return answer


# Cleanup on shutdown
marlo.shutdown()

Multi-Agent Example

import marlo

marlo.init(api_key="mk_abc123")

marlo.agent(name="orchestrator", system_prompt="You coordinate tasks.", tools=[])
marlo.agent(name="researcher", system_prompt="You research topics.", tools=[])
marlo.agent(name="writer", system_prompt="You write content.", tools=[])

with marlo.task(thread_id="doc-123", agent="orchestrator") as main_task:
    main_task.input("Write a report about AI")

    # Delegate to researcher
    with main_task.child(agent="researcher") as research:
        research.input("Research AI trends")
        research.output("AI trends: ...")

    # Delegate to writer
    with main_task.child(agent="writer") as writer:
        writer.input("Write report based on research")
        writer.output("# AI Report\n...")

    main_task.output("Report completed")

Environment Variables

MARLO_API_KEY=your-api-key

Requirements

  • Python 3.11 or later

License

MIT

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

marlo_sdk-0.0.1.tar.gz (137.7 kB view details)

Uploaded Source

Built Distribution

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

marlo_sdk-0.0.1-py3-none-any.whl (176.1 kB view details)

Uploaded Python 3

File details

Details for the file marlo_sdk-0.0.1.tar.gz.

File metadata

  • Download URL: marlo_sdk-0.0.1.tar.gz
  • Upload date:
  • Size: 137.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for marlo_sdk-0.0.1.tar.gz
Algorithm Hash digest
SHA256 17bbedc7daf444f21528f6e74f8bb0eb60976f8e4d384a2855a4ea3f706003e0
MD5 53fa5a93df4e533708e76b3cd6991c69
BLAKE2b-256 723ae6d1f2690afc1a140e5231162e25fe22b35e8bf55d53740f0cfda75ae91f

See more details on using hashes here.

File details

Details for the file marlo_sdk-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: marlo_sdk-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 176.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for marlo_sdk-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 23a9ea13297209e5b02a2f1cc40fad2321faf5a3208ddaa72a890a5b83f72974
MD5 e5c7ac8cfb6142432b202fef5e6ea8af
BLAKE2b-256 6709946697935a8d57e18f4c4a41b097a60979ed3d19829af7368a5d7d5abd4a

See more details on using hashes here.

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