Use the Best Tool to Learn Two Agents

Anthropic has developed the ultimate coding agent, Claude Code, which stands out as the premier tool for learning about agents. My previous methods of reading documentation and source code are now vastly inferior and significantly less efficient than utilizing this powerful tool.

Here is a demo on how it helps me learn two agents SDKs, one is Claude the other is OpenAI.

๐Ÿ“˜ Claude Agent SDK for Python – Quick Learning Guide

๐ŸŽฏ What is it?

The Claude Agent SDK is a Python library that lets you build AI agents powered by Claude. It’s built on top of the same infrastructure that powers Claude Code (the CLI tool you’re using right now).

Key Difference from OpenAI Agents SDK:

  • OpenAI SDK: You manage everything (conversation, tools, state)
  • Claude SDK: Built-in context management, integrated with Claude Code, hooks system

๐Ÿš€ Two Ways to Use It

  1. Simple Mode: query() – One-off Questions, no conversation history needed
  2. Conversation Mode: ClaudeSDKClient – Multi-turn Chat, keep context across queries

๐Ÿ› ๏ธ Custom Tools – The Power Feature

What are Tools? Functions that Claude can call to do things (like your MCP tools: RBICS, NSS, etc.) key benefits is in-progress, no subprocess management like my current MCP server, type-safe, easy to debug and better performance.

๐ŸŽฃ Hooks – Intercept Agent Behavior

Hooks let you run code at specific points in the agent’s execution: there are preToolUse, PosttoolUse, UserPromptSubmit these hook events

โš™๏ธ Configuration: ClaudeAgentOptions

๐Ÿ”— Connecting to Your Existing MCP Server

๐Ÿ“Š Comparison: Claude SDK vs OpenAI Agents SDK

FeatureClaude Agent SDKOpenAI Agents SDK
Context ManagementBuilt-inManual (SQLiteSession)
Tool Definition@tool decorator@function_tool
MCP IntegrationNative, in-processVia subprocess (stdio)
StreamingBuilt-in AsyncIteratorManual setup
HooksYes (PreTool, PostTool)Via Agent lifecycle
Conversation StateClaudeSDKClient managesYou manage Sessions
Azure SupportStandard Claude APICustom client needed

First test run simple query

 import anyio
  from claude_agent_sdk import query

  async def main():
      print("Testing Claude Agent SDK...")
      print("="*60)

      async for message in query(prompt="What is 2 + 2? Just give me the number."):
          print(message)

      print("="*60)
      print("Success! SDK is working.")

  if __name__ == "__main__":
      anyio.run(main)

succeeded:

Response:
------------------------------------------------------------
SystemMessage(subtype='init', data={'type': 'system', 'subtype': 'init', 'cwd': 'C:\\Users\\ncarucci\\Documents\\Gitfolder\\index-solution-agent-claude', 'session_id': '1f0172a1-9607-4c95-a94b-aa2a9ad2708c', 'tools': ['Task', 'Bash', 'Glob', 'Grep', 'ExitPlanMode', 'Read', 'Edit', 'Write', 'NotebookEdit', 'WebFetch', 'TodoWrite', 'WebSearch', 'BashOutput', 'KillShell', 'SlashCommand'], 'mcp_servers': [], 'model': 'claude-sonnet-4-5-20250929', 'permissionMode': 'default', 'slash_commands': ['compact', 'context', 'cost', 'init', 'output-style:new', 'pr-comments', 'release-notes', 'todos', 'review', 'security-review'], 'apiKeySource': 'none', 'output_style': 'default', 'agents': ['general-purpose', 'statusline-setup', 'output-style-setup'], 'uuid': '6941aa07-3eb4-4ced-9793-a22e67da4dae'})
AssistantMessage(content=[TextBlock(text='4')], model='claude-sonnet-4-5-20250929', parent_tool_use_id=None)
29', parent_tool_use_id=None)
ResultMessage(subtype='success', duration_ms=1812, duration_api_ms=1745, is_error=False, num_turns=1, session_id='1f0172a1-9607-4c95-a94b-aa2a9ad2708c', total_cost_usd=0.0361536, usage={'input_tokens': 3, 'cache_creation_input_tokens': 9184, 'cache_read_input_tokens': 5432, 'output_tokens': 5, 'server_tool_use': {'web_search_requests': 0}, 'service_tier': 'standard', 'cache_creation': {'ephemeral_1h_input_tokens': 0, 'ephemeral_5m_input_tokens': 9184}}, result='4')

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.