Initialize Claude Agent with Custom Tools

implementationChallenge

Prompt Content

Start by setting up your development environment for the Claude Agents SDK. Define a `Tool` for fetching simulated crypto transaction data (`get_transaction_details(tx_id: str)`) and another for fetching relevant news articles (`search_crypto_news(query: str)`). Implement basic Python functions that return dummy data for these tools. Then, initialize a Claude agent with these tools, instructing it to monitor for large, suspicious transactions followed by news of scams. Include Python code snippets.

```python
from anthropic import Anthropic
from anthropic.agents import Tool, Agent
import json
import time

# Initialize Anthropic client
client = Anthropic(api_key="YOUR_ANTHROPIC_API_KEY")

# Define a dummy tool for fetching transaction data
def get_transaction_details(tx_id: str) -> str:
    """Fetches details for a given crypto transaction ID."""
    # Simulate fetching data
    if tx_id == "tx3":
        return json.dumps({
            "tx_id": tx_id, "from_addr": "C", "to_addr": "Monero_Mixer", 
            "amount": "1200XMR", "currency": "XMR", "timestamp": "T3"
        })
    return json.dumps({"tx_id": tx_id, "status": "not_found"})

# Define a dummy tool for searching crypto news
def search_crypto_news(query: str) -> str:
    """Searches for crypto news articles related to the query."""
    # Simulate news search
    if "scam" in query.lower() and "whale" in query.lower():
        return json.dumps([{"headline": "Whale loses millions in hardware wallet scam", "content": "A prominent crypto whale reported losing over $282M in BTC and LTC...", "timestamp": "T2.5"}])
    return json.dumps([])

# Create Tool instances
transaction_tool = Tool(name="get_transaction_details", description=get_transaction_details.__doc__, input_schema={"$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": {"tx_id": {"type": "string"}}, "required": ["tx_id"]})
news_tool = Tool(name="search_crypto_news", description=search_crypto_news.__doc__, input_schema={"$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "properties": {"query": {"type": "string"}}, "required": ["query"]})

# Initialize the agent. Your task is to define the agent's prompt and make it use these tools.
# agent = Agent(client=client, tools=[transaction_tool, news_tool], ...)
# response = agent.run("Monitor for suspicious crypto activities and alert on potential scams.")
```

Try this prompt

Open the workspace to execute this prompt with free credits, or use your own API keys for unlimited usage.

Usage Tips

Copy the prompt and paste it into your preferred AI tool (Claude, ChatGPT, Gemini)

Customize placeholder values with your specific requirements and context

For best results, provide clear examples and test different variations