Files
agent-framework/python/samples/02-agents/harness
T
westey bad05a2bdc Python: Harness console for python (#6312)
* Add initial harness console for python

* Add textual to project

* Add planning and approval flows with list selector

* Address PR comments

* Fix list selection bug

* Fix PR #6312 round 2 review comments

- Escape untrusted agent text with rich.markup.escape() in observers
  (text_output, planning_output, reasoning_display) to prevent markup injection
- Remove non-functional 'Always approve' choices from tool_approval.py
  (framework lacks CreateAlwaysApproveToolResponse support)
- Remove textual from root pyproject.toml dev deps (sample-specific)
- Add PEP 723 inline script metadata to harness_research.py
- Narrow except Exception to except NoMatches in list_selection.py

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix build error

* Fix build errors

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
bad05a2bdc ยท 2026-06-09 05:48:35 +00:00
History
..

Harness Agent Samples

This folder demonstrates create_harness_agent โ€” a factory function that builds a pre-configured, batteries-included agent by assembling the full agent pipeline from a chat client.

What is create_harness_agent?

create_harness_agent bundles the following features into a single Agent instance:

Feature Description
Function invocation Automatic tool calling loop
Per-service-call persistence History persisted after every model call
Compaction Context-window management (sliding window + tool result compaction)
TodoProvider Todo list management for planning and tracking
AgentModeProvider Plan/execute mode tracking
MemoryContextProvider File-based durable memory (when memory_store provided)
SkillsProvider File-based skill discovery and progressive loading
OpenTelemetry Built-in observability

Each feature can be disabled or customized via keyword arguments.

Samples

File Description
harness_research.py Interactive research assistant with web search and planning workflow

Running

# Set your Foundry environment variables
export FOUNDRY_PROJECT_ENDPOINT="https://your-project.services.ai.azure.com/api/projects/your-project-name"
export FOUNDRY_MODEL="your-model-deployment-name"

# Authenticate with Azure (required for AzureCliCredential)
az login

# Run the research sample
python samples/02-agents/harness/harness_research.py

Key Concepts

Minimal Setup

create_harness_agent requires only a chat client and token budget parameters:

from agent_framework import create_harness_agent
from agent_framework.foundry import FoundryChatClient
from azure.identity import AzureCliCredential

agent = create_harness_agent(
    client=FoundryChatClient(credential=AzureCliCredential()),
    max_context_window_tokens=128_000,
    max_output_tokens=16_384,
)

Customization

Disable or customize any feature:

agent = create_harness_agent(
    client=client,
    max_context_window_tokens=128_000,
    max_output_tokens=16_384,
    name="my-agent",
    agent_instructions="Custom instructions here.",
    disable_todo=True,          # Skip todo management
    disable_mode=True,          # Skip plan/execute modes
    disable_compaction=True,    # Skip compaction
)

Plan/Execute Workflow

The AgentModeProvider enables a two-phase workflow:

  1. Plan mode โ€” Interactive: the agent asks questions, creates todos, gets approval
  2. Execute mode โ€” Autonomous: the agent works through todos independently