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 openaiSet 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
| Parameter | Type | Default | Description |
|---|---|---|---|
api_key | Optional[str] | None | Morph API key. Uses MORPH_API_KEY if not set. |
base_url | str | "https://api.morphllm.com/v1" | Morph API base URL. |
model | str | "morph-v3-large" | Morph model to use for code editing. |
instructions | Optional[str] | None | Custom instructions for code editing behavior. |
add_instructions | bool | True | Whether to add instructions to the agent. |
Toolkit Functions
| Function | Description |
|---|---|
edit_file | Apply intelligent code modifications using Morph's Fast Apply API. |