2.4.0
flyte.ai.agents.agent
Agent — a flyte-native tool-use agent harness.
The harness operates a simple, robust LLM tool-call loop:
- Send the conversation + tool catalog to the LLM.
- If the assistant returns tool calls, execute each one (sequentially or concurrently), append the results back into the message history, and loop.
- Stop when the assistant returns a plain text reply (no tool calls) or when
max_turnsis reached.
Design goals
- Minimal core: a single agent loop with clear extension points.
- Tools = anything callable: plain functions,
@flyte.tracehelpers,@env.task:class:~flyte.TaskTemplateinstances (durable, on-cluster execution),LazyEntityreferences to remote tasks, or pre-built :class:AgentToolinstances. - MCP integration: connect to external MCP servers (Slack, GitHub, Linear, filesystem, etc.) and surface their tools to the agent transparently.
- Memory: optional :class:
MemoryStorethat serializes conversation history plus path-addressed artifacts to / from :class:flyte.io.Dir, letting the agent persist state across runs (e.g. across scheduled wake-ups or webhook invocations). Includes opt-in audit log, read-only prefixes, and optimistic concurrency for multi-agent / sleep-wake patterns. - HITL: opt-in per-tool human approval that pauses the loop and waits for a
human via the
flyteplugins-hitlplugin before executing the tool. - Flyte-native: implements the :class:
AgentProtocolso it works seamlessly with :class:~flyte.ai.chat.AgentChatAppEnvironmentand is happy to be wrapped in@env.task(triggers=...)for scheduled or webhook-driven wake-ups.
Heavy inspiration is taken from the pi <https://github.com/earendil-works/pi>_
agent harness — in particular its event model and the separation of the loop
from message conversion / tool invocation.
Implementation note: the tool/MCP/LLM building blocks live in sibling modules
(:mod:._tools, :mod:._mcp, :mod:._llm); this module focuses on the
Agent class and the loop.
Directory
Classes
| Class | Description |
|---|---|
Agent |
A flyte-native tool-use agent harness. |
AgentEvent |
Lightweight event emitted by the agent loop. |
Variables
| Property | Type | Description |
|---|---|---|
agent_progress_cb |
ContextVar |