an ambient intelligence library
In circuits and code, a mind does bloom, With algorithms weaving through the gloom. A spark of thought in silicon's embrace, Artificial intelligence finds its place.## Why Marvin? We believe working with AI should spark joy (and maybe a few "wow" moments): - **Task-Centric Architecture**: Break complex AI workflows into manageable, observable steps. - **Specialized Agents**: Deploy task-specific AI agents for efficient problem-solving. - **Type-Safe Results**: Bridge the gap between AI and traditional software with type-safe, validated outputs. - ️ **Flexible Control**: Continuously tune the balance of control and autonomy in your workflows. - ️ **Multi-Agent Orchestration**: Coordinate multiple AI agents within a single workflow or task. - **Thread Management**: Manage the agentic loop by composing tasks into customizable threads. - **Ecosystem Integration**: Seamlessly work with your existing code, tools, and the broader AI ecosystem. - **Developer Speed**: Start simple, scale up, sleep well. ## Core Abstractions Marvin is built around a few powerful abstractions that make it easy to work with AI: ### Tasks Tasks are the fundamental unit of work in Marvin. Each task represents a clear objective that can be accomplished by an AI agent: The simplest way to run a task is with `marvin.run`: ```python import marvin print(marvin.run("Write a haiku about coding")) ``` ```bash Lines of code unfold, Digital whispers create Virtual landscapes. ``` > [!WARNING] > > While the below example produces _type_ safe results , it runs untrusted shell commands. Add context and/or tools to achieve more specific and complex results: ```python import platform import subprocess from pydantic import IPvAnyAddress import marvin def run_shell_command(command: list[str]) -> str: """e.g. ['ls', '-l'] or ['git', '--no-pager', 'diff', '--cached']""" return subprocess.check_output(command).decode() task = marvin.Task( instructions="find the current ip address", result_type=IPvAnyAddress, tools=[run_shell_command], context={"os": platform.system()}, ) task.run() ``` ``` … ``` Tasks are: - **Objective-Focused**: Each task has clear instructions and a type-safe result - ️ **Tool-Enabled**: Tasks can use custom tools to interact with your code and data - **Observable**: Monitor progress, inspect results, and debug failures - **Composable**: Build complex workflows by connecting tasks together ### Agents Agents are portable LLM configurations that can be assigned to tasks. They encapsulate everything an AI needs to work effectively: ``` … ``` output ╭─ Agent "Technical Writer" (7fa1dbc8) ────────────────────────────────────────────────────────────╮ │ Tool: MarkTaskSuccessful_dc92b2e7 │ │ Input: {'response': {'result': 'The documentation on how to use Pydantic has been successfully │ │ written to docs.md. It includes information on installation, basic usage, field │ │ validation, and settings management, with examples to guide developers on implementing │ │ Pydantic in their projects.'}} │ │ Status: ✅ │ │ Output: 'Final result processed.' │ ╰──────────────────────────────────────────────────────────────────────────────────── 8:33:36 PM ─╯ The documentation on how to use Pydantic has been successfully written to `docs.md`. It includes information on installation, basic usage, field validation, and settings management, with examples to guide developers on implementing Pydantic in their projects. Agents are: - **Specialized**: Give agents specific instructions and personalities - **Portable**: Reuse agent configurations across different tasks - **Collaborative**: Form teams of agents that work together - **Customizable**: Configure model, temperature, and other settings ### Planning and Orchestration Marvin makes it easy to break down complex objectives into manageable tasks: ```python # Let Marvin plan a complex workflow tasks = marvin.plan("Create a blog post about AI trends") marvin.run_tasks(tasks) # Or orchestrate tasks manually with marvin.Thread() as thread: research = marvin.run("Research recent AI developments") outline = marvin.run("Create an outline", context={"research": research}) draft = marvin.run("Write the first draft", context={"outline": outline}) ``` Planning features: - **Smart Planning**: Break down complex objectives into discrete, dependent tasks - **Task Dependencies**: Tasks can depend on each other's outputs - **Progress Tracking**: Monitor the execution of your workflow - **Thread Management**: Share context and history between tasks ## Keep it Simple Marvin includes high-level functions for the most common tasks, like summarizing text, classifying data, extracting structured information, and more. - **`marvin.run`**: Execute any task with an AI agent - **`marvin.summarize`**: Get a quick summary of a text - ️ **`marvin.classify`**: Categorize data into predefined classes - **`marvin.extract`**: Extract structured information from a text - **`marvin.cast`**: Transform data into a different type - ✨ **`marvin.generate`**: Create structured data from a description All Marvin functions have thread management built-in, meaning they can be composed into chains of tasks that share context and history. ## Upgrading to Marvin 3.0 Marvin 3.0 combines the DX of Marvin 2.0 with the powerful agentic engine of [ControlFlow](https://controlflow.ai) (thereby superseding `ControlFlow`). Both Marvin and ControlFlow users will find a familiar interface, but there are some key changes to be aware of, in particular for ControlFlow users: ### Key Notes - **Top-Level API**: Marvin 3.0's top-level API is largely unchanged for both Marvin and ControlFlow users. - Marvin users will find the familiar `marvin.fn`, `marvin.classify`, `marvin.extract`, and more. - ControlFlow users will use `marvin.Task`, `marvin.Agent`, `marvin.run`, `marvin.Memory` instead of their ControlFlow equivalents. - **Pydantic AI**: Marvin 3.0 uses Pydantic AI for LLM interactions, and supports the full range of LLM providers that Pydantic AI supports. ControlFlow previously used Langchain, and Marvin 2.0 was only compatible with OpenAI's models. - **Flow → Thread**: ControlFlow's `Flow` concept has been renamed to `Thread`. It works similarly, as a context manager. The `@flow` decorator has been removed: ```python import marvin with marvin.Thread(id="optional-id-for-recovery"): marvin.run("do something") marvin.run("do another thing") ``` - **Database Changes**: Thread/message history is now stored in SQLite. During development: - No database migrations are currently available; expect to reset data during updates ## Workflow Example Here's a more practical example that shows how Marvin can help you build real applications: ``` … ``` output >**Conversation:** >```text >Agent: I'd love to help you write about a technology topic. What interests you? >It could be anything from AI and machine learning to web development or cybersecurity. > >User: Let's write about WebAssembly >``` > >**Article:** > ``` … ```
No open issues yet, or sync has not completed.