Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add anthropic native support #5695

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

add anthropic native support #5695

wants to merge 2 commits into from

Conversation

victordibia
Copy link
Collaborator

@victordibia victordibia commented Feb 25, 2025

Claude 3.7 just came out. Its a pretty capable model and it would be great to support it in Autogen.
This will could augment the already excellent support we have for Anthropic via the SKAdapters in the following ways

  • Based on the ChatCompletion API similar to the ollama and openai client
  • Configurable/serializable (can be dumped) .. this means it can be used easily in AGS.

What is Supported

Uploading anthropic_tool_calling.mov…

  • streaming
  • tool callign / function calling
  • drop in integration with assistant agent.
from dotenv import load_dotenv
import os 

load_dotenv()

from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_ext.models.anthropic import AnthropicChatCompletionClient 
model_client =   AnthropicChatCompletionClient(
        model="claude-3-7-sonnet-20250219" 
    )

async def get_weather(city: str) -> str:
    """Get the weather for a given city."""
    return f"The weather in {city} is 73 degrees and Sunny."

 
agent = AssistantAgent(
    name="weather_agent",
    model_client=model_client,
    tools=[get_weather],
    system_message="You are a helpful assistant.", 
    # model_client_stream=True,   
)

# Run the agent and stream the messages to the console.
async def main() -> None:
    await Console(agent.run_stream(task="What is the weather in New York?"))
await main()

result

messages = [
    UserMessage(content="Write a very short story about a dragon.", source="user"),
]

# Create a stream.
stream = model_client.create_stream(messages=messages)

# Iterate over the stream and print the responses.
print("Streamed responses:")
async for response in stream:  # type: ignore
    if isinstance(response, str):
        # A partial response is a string.
        print(response, flush=True, end="")
    else:
        # The last response is a CreateResult object with the complete message.
        print("\n\n------------\n")
        print("The complete response:", flush=True)
        print(response.content, flush=True)
        print("\n\n------------\n")
        print("The token usage was:", flush=True)
        print(response.usage, flush=True)

TBD

tests

Why are these changes needed?

Related issue number

Checks

Copy link

codecov bot commented Feb 25, 2025

Codecov Report

Attention: Patch coverage is 0% with 468 lines in your changes missing coverage. Please review.

Project coverage is 72.45%. Comparing base (a14aeab) to head (769c676).

Files with missing lines Patch % Lines
.../autogen_ext/models/anthropic/_anthropic_client.py 0.00% 400 Missing ⚠️
...rc/autogen_ext/models/anthropic/config/__init__.py 0.00% 47 Missing ⚠️
...xt/src/autogen_ext/models/anthropic/_model_info.py 0.00% 18 Missing ⚠️
...n-ext/src/autogen_ext/models/anthropic/__init__.py 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5695      +/-   ##
==========================================
- Coverage   75.66%   72.45%   -3.21%     
==========================================
  Files         171      175       +4     
  Lines       10576    11044     +468     
==========================================
  Hits         8002     8002              
- Misses       2574     3042     +468     
Flag Coverage Δ
unittests 72.45% <0.00%> (-3.21%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant