Morph

MorphTools provides advanced code editing capabilities using Morph's Fast Apply API for intelligent code modifications.

Prerequisites

The following examples require the openai library:

uv pip install agno -U openai

Set the MORPH_API_KEY environment variable:

export MORPH_API_KEY="your-morph-api-key"

The Agent model uses an OpenAI key, separately from any toolkit provider credentials.

Set OpenAI Key

Set your OPENAI_API_KEY as an environment variable. You can get one from OpenAI.

export OPENAI_API_KEY=sk-***

Example

The following agent can perform intelligent code editing using Morph:

import tempfile
from pathlib import Path

from agno.agent import Agent
from agno.tools.models.morph import MorphTools

workspace = Path(tempfile.mkdtemp(prefix="morph_demo_"))
target = workspace / "totals.py"
target.write_text("def total(values):\n    result = 0\n    for value in values:\n        result += value\n    return result\n")

agent = Agent(
    instructions=[
        "You are a code editing assistant using Morph's advanced AI capabilities",
        "Help users modify, improve, and refactor their code intelligently",
        "Apply code changes efficiently while maintaining code quality",
        "Provide explanations for the modifications made",
    ],
    tools=[MorphTools()],
)

agent.print_response(
    f"Edit {target}: add list[int] and int type hints and use sum(values).",
    stream=True,
)

Toolkit Params

ParameterTypeDefaultDescription
api_keyOptional[str]NoneMorph API key. Uses MORPH_API_KEY if not set.
base_urlstr"https://api.morphllm.com/v1"Morph API base URL.
modelstr"morph-v3-large"Morph model to use for code editing.
instructionsOptional[str]NoneCustom instructions for code editing behavior.
add_instructionsboolTrueWhether to add instructions to the agent.

Toolkit Functions

FunctionDescription
edit_fileApply intelligent code modifications using Morph's Fast Apply API.

Developer Resources