Skip to content

Claude Code Provider Does Not Capture Response Text — HarnessResult.result is always 'None' due to Incorrect Message Type Check #252

@Sridhar-Vetrivel

Description

@Sridhar-Vetrivel

Describe the bug

Bug Report: result.text Always Returns Empty
Summary
The Claude Code provider (sdk/python/agentfield/harness/providers/claude.py) never captures the response text, so HarnessResult.result is always None and result.text always returns "". This test case is for basic prompt, without schema.
Root Cause
The provider waits for a message with type == "result", but the Claude Agent SDK never sends that. Instead, it sends a message with subtype == "success" (no type field). Because the condition never matches, result_text stays None.
In the output messages you can see:
{'subtype': 'success', ..., 'result': "Here's a simple Python function..."}
There is no type field here — only subtype.

Steps to reproduce

  1. Create a python file(TC-01.py)
    '''
    Test Case: TC-01
    Description: Test basic functionality of the harness with a simple math question.
    Basic Prompt, no schema
    Verify .harness() returns a HarnessResult with .text set and no error.
    '''
import asyncio
from agentfield import Agent
from agentfield.types import HarnessConfig

async def test():
    agent = Agent(
        node_id="test-basic",
        harness_config=HarnessConfig(provider="claude-code"),
        auto_register=False,
    )
    result = await agent.harness(
        "Write a python function that adds two numbers (2, 2) together and return the result."
    )
    print("HarnessResult:",result)
    print("is_error:", result.is_error)
    print("text:", result.text)  # <-- Returning None, which is unexpected
    # print("message:", result.messages)
    print("num_turns:", result.num_turns)
    print("duration_ms:", result.duration_ms)
    assert not result.is_error
    print("PASS")

asyncio.run(test())
  1. Run 'python TC-01.py' in the terminal

  2. Sample Output
    !!!Ensure the final result is printed to stdout for harness capture None <--- This line is printed from claude.py which I have written as print statement to find out and verify the issue.
    HarnessResult: HarnessResult(result=None, parsed=None, is_error=False, ......,
    messages=[{'subtype': 'init', 'data': {'type': 'system', 'subtype': 'init', 'cwd': '/home/sridharvetrivel/harness-test', 'session_id': '27ad48b4-fdab-4384-ab22-dc53dff12be6', 'tools': ['Task', 'TaskOutput', 'Bash', 'Glob', 'Grep', 'ExitPlanMode', 'Read', 'Edit', 'Write', 'NotebookEdit', 'WebFetch', 'TodoWrite', 'WebSearch', 'TaskStop', 'AskUserQuestion', 'Skill', 'EnterPlanMode', 'EnterWorktree', 'CronCreate', 'CronDelete', 'CronList', 'ToolSearch'], 'mcp_servers': [{'name': 'claude.ai Gmail', 'status': 'needs-auth'}, {'name': 'claude.ai Google Calendar', 'status': 'needs-auth'}, {'name': 'claude.ai Hugging Face', 'status': 'needs-auth'}], 'model': 'claude-sonnet-4-6', 'permissionMode': 'default', 'slash_commands': ['keybindings-help', 'debug', 'simplify', 'batch', 'loop', 'claude-api', 'compact', 'context', 'cost', 'heapdump', 'init', 'pr-comments', 'release-notes', 'review', 'security-review', 'extra-usage', 'insights'], 'apiKeySource': 'none', 'claude_code_version': '2.1.71', 'output_style': 'default', 'agents': ['general-purpose', 'statusline-setup', 'Explore', 'Plan'], 'skills': ['keybindings-help', 'debug', 'simplify', 'batch', 'loop', 'claude-api'], 'plugins': [], 'uuid': '063471bc-0d16-4406-9e5f-dc82f16e56ee', 'fast_mode_state': 'off'}}, {'content': [ThinkingBlock(thinking='Simple Python function request.', signature='eysks....')], 'model': 'claude-sonnet-4-6', 'parent_tool_use_id': None, 'error': None}, {'content': [TextBlock(text="Here's a simple Python function that adds two numbers together:\n\npython\ndef add_numbers(a, b):\n return a + b\n\nresult = add_numbers(2, 2)\nprint(result) # Output: 4\n\n\nBreakdown:\n- add_numbers(a, b) — defines the function with two parameters.\n- return a + b — adds the two numbers and returns the result.\n- add_numbers(2, 2) — calls the function with 2 and 2, returning 4.")], 'model': 'claude-sonnet-4-6', 'parent_tool_use_id': None, 'error': None}, {'subtype': 'success', 'duration_ms': 2807, 'duration_api_ms': 2792, 'is_error': False, 'num_turns': 1, 'session_id': '27ad48b4-fdab-4384-ab22-dc53dff12be6', 'stop_reason': 'end_turn', 'total_cost_usd': 0.008761999999999999, 'usage': {'input_tokens': 3, 'cache_creation_input_tokens': 0, 'cache_read_input_tokens': 9944, 'output_tokens': 151, 'server_tool_use': {'web_search_requests': 0, 'web_fetch_requests': 0}, 'service_tier': 'standard', 'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 0}, 'inference_geo': '', 'iterations': [], 'speed': 'standard'}, 'result': "Here's a simple Python function that adds two numbers together:\n\npython\ndef add_numbers(a, b):\n return a + b\n\nresult = add_numbers(2, 2)\nprint(result) # Output: 4\n\n\nBreakdown:\n- add_numbers(a, b) — defines the function with two parameters.\n- return a + b — adds the two numbers and returns the result.\n- add_numbers(2, 2) — calls the function with 2 and 2, returning 4.", 'structured_output': None}])
    is_error: False
    text:
    num_turns: 0
    duration_ms: 5529
    PASS

Expected behavior

text: null <-- This should display the response provided by the LLM
text: Here's a simple Python function that adds two numbers together:

def add_two_numbers(a, b):
    return a + b

result = add_two_numbers(2, 2)
print(result)  # Output: 4

How it works:

  • add_two_numbers(a, b) — takes two parameters, a and b
  • return a + b — adds them together and returns the result
  • Calling it with (2, 2) returns 4

Environment

AgentField Control Plane
  Version:    0.1.48-rc.2
  Commit:     881b1aa
  Built:      2026-03-09T07:26:01Z
  Go version: go1.24.2
  OS/Arch:    linux/amd64

Additional context

This test case is for basic prompt, Without schema.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions