Skip to content

A programming framework for agentic AI

add anthropic native support (#5695)

Victor Dibia05fc763b8a36
diff --git a/python/packages/autogen-core/src/autogen_core/models/_model_client.py b/python/packages/autogen-core/src/autogen_core/models/_model_client.py
index a378f29a3..3d157d240 100644
--- a/python/packages/autogen-core/src/autogen_core/models/_model_client.py
+++ b/python/packages/autogen-core/src/autogen_core/models/_model_client.py
@@ -32,6 +32,7 @@ class ModelFamily:
CLAUDE_3_OPUS = "claude-3-opus"
CLAUDE_3_5_HAIKU = "claude-3.5-haiku"
CLAUDE_3_5_SONNET = "claude-3.5-sonnet"
+ CLAUDE_3_7_SONNET = "claude-3.7-sonnet"
UNKNOWN = "unknown"
ANY: TypeAlias = Literal[
diff --git a/python/packages/autogen-ext/src/autogen_ext/models/anthropic/__init__.py b/python/packages/autogen-ext/src/autogen_ext/models/anthropic/__init__.py
new file mode 100644
index 000000000..75365d781
--- /dev/null
+++ b/python/packages/autogen-ext/src/autogen_ext/models/anthropic/__init__.py
@@ -0,0 +1,14 @@
+from ._anthropic_client import AnthropicChatCompletionClient, BaseAnthropicChatCompletionClient
+from .config import (
+ AnthropicClientConfiguration,
+ AnthropicClientConfigurationConfigModel,
+ CreateArgumentsConfigModel,
+)
+
+__all__ = [
+ "AnthropicChatCompletionClient",
+ "BaseAnthropicChatCompletionClient",
+ "AnthropicClientConfiguration",
+ "AnthropicClientConfigurationConfigModel",
+ "CreateArgumentsConfigModel",
+]
diff --git a/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py b/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py
new file mode 100644
index 000000000..3829d8dcf
--- /dev/null
+++ b/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py
@@ -0,0 +1,1003 @@
+import asyncio
+import base64
+import inspect
+import json
+import logging
+import re
+import warnings
+
+# from asyncio import Task
+from typing import (
+ Any,
+ AsyncGenerator,
+ Coroutine,
+ Dict,
+ List,
+ Literal,
+ Mapping,
+ Optional,
+ Sequence,
+ Set,
+ Union,
+ cast,
+)
+
+import tiktoken
+from anthropic import AsyncAnthropic, AsyncStream
+from anthropic.types import (
+ ContentBlock,
+ ImageBlockParam,
+ Message,
+ MessageParam,
+ RawMessageStreamEvent, # type: ignore
+ TextBlock,
+ TextBlockParam,
+ ToolParam,
+ ToolResultBlockParam,
+ ToolUseBlock,
+)
+from anthropic.types.image_block_param import Source
+from autogen_core import (
+ EVENT_LOGGER_NAME,
+ TRACE_LOGGER_NAME,
+ CancellationToken,
+ Component,
+ FunctionCall,
+ Image,
+ MessageHandlerContext,
+)
+from autogen_core.logging import LLMCallEvent
+from autogen_core.models import (
+ AssistantMessage,
+ ChatCompletionClient,
+ CreateResult,
+ FinishReasons,
+ FunctionExecutionResultMessage,
+ LLMMessage,
+ ModelCapabilities, # type: ignore
+ ModelInfo,
+ RequestUsage,
+ SystemMessage,
+ UserMessage,
+ validate_model_info,
+)
+from autogen_core.tools import Tool, ToolSchema
+from typing_extensions import Self, Unpack
+
+from . import _model_info
+from .config import AnthropicClientConfiguration, AnthropicClientConfigurationConfigModel
+
+logger = logging.getLogger(EVENT_LOGGER_NAME)
+trace_logger = logging.getLogger(TRACE_LOGGER_NAME)
+
+# Common parameters for message creation
+anthropic_message_params = {
+ "system",
+ "messages",
+ "max_tokens",
+ "temperature",
+ "top_p",
+ "top_k",
+ "stop_sequences",
+ "tools",
+ "tool_choice",
+ "stream",
+ "metadata",
+}
+disallowed_create_args = {"stream", "messages"}
+required_create_args: Set[str] = {"model"}
+
+anthropic_init_kwargs = set(inspect.getfullargspec(AsyncAnthropic.__init__).kwonlyargs)
+
+
+def _anthropic_client_from_config(config: Mapping[str, Any]) -> AsyncAnthropic:
+ # Filter config to only include valid parameters
+ client_config = {k: v for k, v in config.items() if k in anthropic_init_kwargs}
+ return AsyncAnthropic(**client_config)
+
+
+def _create_args_from_config(config: Mapping[str, Any]) -> Dict[str, Any]:
+ create_args = {k: v for k, v in config.items() if k in anthropic_message_params or k == "model"}
+ create_args_keys = set(create_args.keys())
+
+ if not required_create_args.issubset(create_args_keys):
+ raise ValueError(f"Required create args are missing: {required_create_args - create_args_keys}")
+
+ if disallowed_create_args.intersection(create_args_keys):
+ raise ValueError(f"Disallowed create args are present: {disallowed_create_args.intersection(create_args_keys)}")
+
+ return create_args
+
+
+def type_to_role(message: LLMMessage) -> str:
+ if isinstance(message, SystemMessage):
+ return "system"
+ elif isinstance(message, UserMessage):
+ return "user"
+ elif isinstance(message, AssistantMessage):
+ return "assistant"
+ else:
+ return "tool"
+
+
+def get_mime_type_from_image(image: Image) -> Literal["image/jpeg", "image/png", "image/gif", "image/webp"]:
+ """Get a valid Anthropic media type from an Image object."""
+ # Get base64 data first
+ base64_data = image.to_base64()
+
+ # Decode the base64 string
+ image_data = base64.b64decode(base64_data)
+
+ # Check the first few bytes for known signatures
+ if image_data.startswith(b"\xff\xd8\xff"):
+ return "image/jpeg"
+ elif image_data.startswith(b"\x89PNG\r\n\x1a\n"):
+ return "image/png"
+ elif image_data.startswith(b"GIF87a") or image_data.startswith(b"GIF89a"):
+ return "image/gif"
+ elif image_data.startswith(b"RIFF") and image_data[8:12] == b"WEBP":
+ return "image/webp"
+ else:
+ # Default to JPEG as a fallback
+ return "image/jpeg"
+
+
+def user_message_to_anthropic(message: UserMessage) -> MessageParam:
+ assert_valid_name(message.source)
+
+ if isinstance(message.content, str):
+ return {
+ "role": "user",
+ "content": message.content,
+ }
+ else:
+ blocks: List[Union[TextBlockParam, ImageBlockParam]] = []
+
+ for part in message.content:
+ if isinstance(part, str):
+ blocks.append(TextBlockParam(type="text", text=part))
+ elif isinstance(part, Image):
+ blocks.append(
+ ImageBlockParam(
+ type="image",
+ source=Source(
+ type="base64",
+ media_type=get_mime_type_from_image(part),
+ data=part.to_base64(),
+ ),
+ )
+ )
+ else:
+ raise ValueError(f"Unknown content type: {part}")
+
+ return {
+ "role": "user",
+ "content": blocks,
+ }
+
+
+def system_message_to_anthropic(message: SystemMessage) -> str:
+ return message.content
+
+
+def assistant_message_to_anthropic(message: AssistantMessage) -> MessageParam:
+ assert_valid_name(message.source)
+
+ if isinstance(message.content, list):
+ # Tool calls
+ tool_use_blocks: List[ToolUseBlock] = []
+
+ for func_call in message.content:
+ # Parse the arguments and convert to dict if it's a JSON string
+ args = func_call.arguments
+ if isinstance(args, str):
+ try:
+ args_dict = json.loads(args)
+ except json.JSONDecodeError:
+ args_dict = {"text": args}
+ else:
+ args_dict = args
+
+ tool_use_blocks.append(
+ ToolUseBlock(
+ type="tool_use",
+ id=func_call.id,
+ name=func_call.name,
+ input=args_dict,
+ )
+ )
+
+ # Include thought if available
+ content_blocks: List[ContentBlock] = []
+ if hasattr(message, "thought") and message.thought is not None:
+ content_blocks.append(TextBlock(type="text", text=message.thought))
+
+ content_blocks.extend(tool_use_blocks)
+
+ return {
+ "role": "assistant",
+ "content": content_blocks,
+ }
+ else:
+ # Simple text content
+ return {
+ "role": "assistant",
+ "content": message.content,
+ }
+
+
+def tool_message_to_anthropic(message: FunctionExecutionResultMessage) -> List[MessageParam]:
+ # Create a single user message containing all tool results
+ content_blocks: List[ToolResultBlockParam] = []
+
+ for result in message.content:
+ content_blocks.append(
+ ToolResultBlockParam(
+ type="tool_result",
+ tool_use_id=result.call_id,
+ content=result.content,
+ )
+ )
+
+ return [
+ {
+ "role": "user", # Changed from "tool" to "user"
+ "content": content_blocks,
+ }
+ ]
+
+
+def to_anthropic_type(message: LLMMessage) -> Union[str, List[MessageParam], MessageParam]:
+ if isinstance(message, SystemMessage):
+ return system_message_to_anthropic(message)
+ elif isinstance(message, UserMessage):
+ return user_message_to_anthropic(message)
+ elif isinstance(message, AssistantMessage):
+ return assistant_message_to_anthropic(message)
+ else:
+ return tool_message_to_anthropic(message)
+
+
+def convert_tools(tools: Sequence[Tool | ToolSchema]) -> List[ToolParam]:
+ result: List[ToolParam] = []
+
+ for tool in tools:
+ if isinstance(tool, Tool):
+ tool_schema = tool.schema
+ else:
+ assert isinstance(tool, dict)
+ tool_schema = tool
+
+ # Convert parameters to match Anthropic's schema format
+ tool_params: Dict[str, Any] = {}
+ if "parameters" in tool_schema:
+ params = tool_schema["parameters"]
+
+ # Transfer properties
+ if "properties" in params:
+ tool_params["properties"] = params["properties"]
+
+ # Transfer required fields
+ if "required" in params:
+ tool_params["required"] = params["required"]
+
+ # Handle schema type
+ if "type" in params:
+ tool_params["type"] = params["type"]
+ else:
+ tool_params["type"] = "object"
+
+ result.append(
+ ToolParam(
+ name=tool_schema["name"],
+ input_schema=tool_params,
+ description=tool_schema.get("description", ""),
+ )
+ )
+
+ # Check if the tool has a valid name
+ assert_valid_name(tool_schema["name"])
+
+ return result
+
+
+def normalize_name(name: str) -> str:
+ """
+
+ def __init__(self, **kwargs: Unpack[AnthropicClientConfiguration]):
+ if "model" not in kwargs:
+ raise ValueError("model is required for AnthropicChatCompletionClient")
+
+ self._raw_config: Dict[str, Any] = dict(kwargs).copy()
+ copied_args = dict(kwargs).copy()
+
+ model_info: Optional[ModelInfo] = None
+ if "model_info" in kwargs:
+ model_info = kwargs["model_info"]
+ del copied_args["model_info"]
+
+ client = _anthropic_client_from_config(copied_args)
+ create_args = _create_args_from_config(copied_args)
+
+ super().__init__(
+ client=client,
+ create_args=create_args,
+ model_info=model_info,
+ )
+
+ def __getstate__(self) -> Dict[str, Any]:
+ state = self.__dict__.copy()
+ state["_client"] = None
+ return state
+
+ def __setstate__(self, state: Dict[str, Any]) -> None:
+ self.__dict__.update(state)
+ self._client = _anthropic_client_from_config(state["_raw_config"])
+
+ def _to_config(self) -> AnthropicClientConfigurationConfigModel:
+ copied_config = self._raw_config.copy()
+ return AnthropicClientConfigurationConfigModel(**copied_config)
+
+ @classmethod
+ def _from_config(cls, config: AnthropicClientConfigurationConfigModel) -> Self:
+ copied_config = config.model_copy().model_dump(exclude_none=True)
+ return cls(**copied_config)
+ Normalize names by replacing invalid characters with underscore.
+ """
+ return re.sub(r"[^a-zA-Z0-9_-]", "_", name)[:64]
+
+
+def assert_valid_name(name: str) -> str:
+ """
+ Ensure that configured names are valid, raises ValueError if not.
+ """
+ if not re.match(r"^[a-zA-Z0-9_-]+$", name):
+ raise ValueError(f"Invalid name: {name}. Only letters, numbers, '_' and '-' are allowed.")
+ if len(name) > 64:
+ raise ValueError(f"Invalid name: {name}. Name must be less than 64 characters.")
+ return name
+
+
+def normalize_stop_reason(stop_reason: str | None) -> FinishReasons:
+ if stop_reason is None:
+ return "unknown"
+
+ # Convert to lowercase for comparison
+ stop_reason = stop_reason.lower()
+
+ # Map Anthropic stop reasons to standard reasons
+ KNOWN_STOP_MAPPINGS: Dict[str, FinishReasons] = {
+ "end_turn": "stop",
+ "max_tokens": "length",
+ "stop_sequence": "stop",
+ "tool_use": "function_calls",
+ }
+
+ return KNOWN_STOP_MAPPINGS.get(stop_reason, "unknown")
+
+
+def _add_usage(usage1: RequestUsage, usage2: RequestUsage) -> RequestUsage:
+ return RequestUsage(
+ prompt_tokens=usage1.prompt_tokens + usage2.prompt_tokens,
+ completion_tokens=usage1.completion_tokens + usage2.completion_tokens,
+ )
+
+
+class BaseAnthropicChatCompletionClient(ChatCompletionClient):
+ def __init__(
+ self,
+ client: AsyncAnthropic,
+ *,
+ create_args: Dict[str, Any],
+ model_info: Optional[ModelInfo] = None,
+ ):
+ self._client = client
+
+ if model_info is None:
+ try:
+ self._model_info = _model_info.get_info(create_args["model"])
+ except KeyError as err:
+ raise ValueError("model_info is required when model name is not recognized") from err
+ else:
+ self._model_info = model_info
+
+ # Validate model_info
+ validate_model_info(self._model_info)
+
+ self._create_args = create_args
+ self._total_usage = RequestUsage(prompt_tokens=0, completion_tokens=0)
+ self._actual_usage = RequestUsage(prompt_tokens=0, completion_tokens=0)
+
+ async def create(
+ self,
+ messages: Sequence[LLMMessage],
+ *,
+ tools: Sequence[Tool | ToolSchema] = [],
+ json_output: Optional[bool] = None,
+ extra_create_args: Mapping[str, Any] = {},
+ cancellation_token: Optional[CancellationToken] = None,
+ ) -> CreateResult:
+ # Copy create args and update with extra args
+ create_args = self._create_args.copy()
+ create_args.update(extra_create_args)
+
+ # Check for vision capability if images are present
+ if self.model_info["vision"] is False:
+ for message in messages:
+ if isinstance(message, UserMessage):
+ if isinstance(message.content, list) and any(isinstance(x, Image) for x in message.content):
+ raise ValueError("Model does not support vision and image was provided")
+
+ # Handle JSON output format
+ if json_output is not None:
+ if self.model_info["json_output"] is False and json_output is True:
+ raise ValueError("Model does not support JSON output")
+
+ if json_output is True:
+ create_args["response_format"] = {"type": "json_object"}
+
+ # Process system message separately
+ system_message = None
+ anthropic_messages: List[MessageParam] = []
+
+ for message in messages:
+ if isinstance(message, SystemMessage):
+ if system_message is not None:
+ raise ValueError("Multiple system messages are not supported")
+ system_message = to_anthropic_type(message)
+ else:
+ anthropic_message = to_anthropic_type(message)
+ if isinstance(anthropic_message, list):
+ anthropic_messages.extend(anthropic_message)
+ elif isinstance(anthropic_message, str):
+ msg = MessageParam(
+ role="user" if isinstance(message, UserMessage) else "assistant", content=anthropic_message
+ )
+ anthropic_messages.append(msg)
+ else:
+ anthropic_messages.append(anthropic_message)
+
+ # Check for function calling support
+ if self.model_info["function_calling"] is False and len(tools) > 0:
+ raise ValueError("Model does not support function calling")
+
+ # Set up the request
+ request_args: Dict[str, Any] = {
+ "model": create_args["model"],
+ "messages": anthropic_messages,
+ "max_tokens": create_args.get("max_tokens", 4096),
+ "temperature": create_args.get("temperature", 1.0),
+ }
+
+ # Add system message if present
+ if system_message is not None:
+ request_args["system"] = system_message
+
+ has_tool_results = any(isinstance(msg, FunctionExecutionResultMessage) for msg in messages)
+
+ # Store and add tools if present
+ if len(tools) > 0:
+ converted_tools = convert_tools(tools)
+ self._last_used_tools = converted_tools
+ request_args["tools"] = converted_tools
+ elif has_tool_results:
+ # anthropic requires tools to be present even if there is any tool use
+ request_args["tools"] = self._last_used_tools
+
+ # Optional parameters
+ for param in ["top_p", "top_k", "stop_sequences", "metadata"]:
+ if param in create_args:
+ request_args[param] = create_args[param]
+
+ # Execute the request
+ future: asyncio.Task[Message] = asyncio.ensure_future(self._client.messages.create(**request_args)) # type: ignore
+
+ if cancellation_token is not None:
+ cancellation_token.link_future(future) # type: ignore
+
+ result: Message = cast(Message, await future) # type: ignore
+
+ # Extract usage statistics
+ usage = RequestUsage(
+ prompt_tokens=result.usage.input_tokens,
+ completion_tokens=result.usage.output_tokens,
+ )
+
+ # Log the event if in a handler context
+ try:
+ agent_id = MessageHandlerContext.agent_id()
+ except RuntimeError:
+ agent_id = None
+
+ logger.info(
+ LLMCallEvent(
+ messages=cast(Dict[str, Any], anthropic_messages),
+ response=result.model_dump(),
+ prompt_tokens=usage.prompt_tokens,
+ completion_tokens=usage.completion_tokens,
+ agent_id=agent_id,
+ )
+ )
+
+ # Process the response
+ content: Union[str, List[FunctionCall]]
+ thought = None
+
+ # Check if the response includes tool uses
+ tool_uses = [block for block in result.content if getattr(block, "type", None) == "tool_use"]
+
+ if tool_uses:
+ # Handle tool use response
+ content = []
+
+ # Check for text content that should be treated as thought
+ text_blocks: List[TextBlock] = [block for block in result.content if isinstance(block, TextBlock)]
+ if text_blocks:
+ thought = "".join([block.text for block in text_blocks])
+
+ # Process tool use blocks
+ for tool_use in tool_uses:
+ if isinstance(tool_use, ToolUseBlock):
+ tool_input = tool_use.input
+ if isinstance(tool_input, dict):
+ tool_input = json.dumps(tool_input)
+ else:
+ tool_input = str(tool_input) if tool_input is not None else ""
+
+ content.append(
+ FunctionCall(
+ id=tool_use.id,
+ name=normalize_name(tool_use.name),
+ arguments=tool_input,
+ )
+ )
+ else:
+ # Handle text response
+ content = "".join([block.text if isinstance(block, TextBlock) else "" for block in result.content])
+
+ # Create the final result
+ response = CreateResult(
+ finish_reason=normalize_stop_reason(result.stop_reason),
+ content=content,
+ usage=usage,
+ cached=False,
+ thought=thought,
+ )
+
+ # Update usage statistics
+ self._total_usage = _add_usage(self._total_usage, usage)
+ self._actual_usage = _add_usage(self._actual_usage, usage)
+
+ return response
+
+ async def create_stream(
+ self,
+ messages: Sequence[LLMMessage],
+ *,
+ tools: Sequence[Tool | ToolSchema] = [],
+ json_output: Optional[bool] = None,
+ extra_create_args: Mapping[str, Any] = {},
+ cancellation_token: Optional[CancellationToken] = None,
+ max_consecutive_empty_chunk_tolerance: int = 0,
+ ) -> AsyncGenerator[Union[str, CreateResult], None]:
+ """
+ Creates an AsyncGenerator that yields a stream of completions based on the provided messages and tools.
+ """
+ # Copy create args and update with extra args
+ create_args = self._create_args.copy()
+ create_args.update(extra_create_args)
+
+ # Check for vision capability if images are present
+ if self.model_info["vision"] is False:
+ for message in messages:
+ if isinstance(message, UserMessage):
+ if isinstance(message.content, list) and any(isinstance(x, Image) for x in message.content):
+ raise ValueError("Model does not support vision and image was provided")
+
+ # Handle JSON output format
+ if json_output is not None:
+ if self.model_info["json_output"] is False and json_output is True:
+ raise ValueError("Model does not support JSON output")
+
+ if json_output is True:
+ create_args["response_format"] = {"type": "json_object"}
+
+ # Process system message separately
+ system_message = None
+ anthropic_messages: List[MessageParam] = []
+
+ for message in messages:
+ if isinstance(message, SystemMessage):
+ if system_message is not None:
+ raise ValueError("Multiple system messages are not supported")
+ system_message = to_anthropic_type(message)
+ else:
+ anthropic_message = to_anthropic_type(message)
+ if isinstance(anthropic_message, list):
+ anthropic_messages.extend(anthropic_message)
+ elif isinstance(anthropic_message, str):
+ msg = MessageParam(
+ role="user" if isinstance(message, UserMessage) else "assistant", content=anthropic_message
+ )
+ anthropic_messages.append(msg)
+ else:
+ anthropic_messages.append(anthropic_message)
+
+ # Check for function calling support
+ if self.model_info["function_calling"] is False and len(tools) > 0:
+ raise ValueError("Model does not support function calling")
+
+ # Set up the request
+ request_args: Dict[str, Any] = {
+ "model": create_args["model"],
+ "messages": anthropic_messages,
+ "max_tokens": create_args.get("max_tokens", 4096),
+ "temperature": create_args.get("temperature", 1.0),
+ "stream": True,
+ }
+
+ # Add system message if present
+ if system_message is not None:
+ request_args["system"] = system_message
+
+ # Check if any message is a tool result
+ has_tool_results = any(isinstance(msg, FunctionExecutionResultMessage) for msg in messages)
+
+ # Add tools if present
+ if len(tools) > 0:
+ converted_tools = convert_tools(tools)
+ self._last_used_tools = converted_tools
+ request_args["tools"] = converted_tools
+ elif has_tool_results:
+ request_args["tools"] = self._last_used_tools
+
+ # Optional parameters
+ for param in ["top_p", "top_k", "stop_sequences", "metadata"]:
+ if param in create_args:
+ request_args[param] = create_args[param]
+
+ # Stream the response
+ stream_future: asyncio.Task[AsyncStream[RawMessageStreamEvent]] = asyncio.ensure_future(
+ cast(Coroutine[Any, Any, AsyncStream[RawMessageStreamEvent]], self._client.messages.create(**request_args))
+ )
+
+ if cancellation_token is not None:
+ cancellation_token.link_future(stream_future) # type: ignore
+
+ stream: AsyncStream[RawMessageStreamEvent] = cast(AsyncStream[RawMessageStreamEvent], await stream_future) # type: ignore
+
+ text_content: List[str] = []
+ tool_calls: Dict[str, Dict[str, Any]] = {} # Track tool calls by ID
+ current_tool_id: Optional[str] = None
+ input_tokens: int = 0
+ output_tokens: int = 0
+ stop_reason: Optional[str] = None
+
+ # Process the stream
+ async for chunk in stream:
+ # Handle different event types
+ if chunk.type == "content_block_start":
+ if chunk.content_block.type == "tool_use":
+ # Start of a tool use block
+ current_tool_id = chunk.content_block.id
+ tool_calls[current_tool_id] = {
+ "id": chunk.content_block.id,
+ "name": chunk.content_block.name,
+ "input": "", # Will be populated from deltas
+ }
+
+ elif chunk.type == "content_block_delta":
+ if hasattr(chunk.delta, "type") and chunk.delta.type == "text_delta":
+ # Handle text content
+ delta_text = chunk.delta.text
+ text_content.append(delta_text)
+ if delta_text:
+ yield delta_text
+
+ # Handle tool input deltas - they come as InputJSONDelta
+ elif hasattr(chunk.delta, "type") and chunk.delta.type == "input_json_delta":
+ if current_tool_id is not None and hasattr(chunk.delta, "partial_json"):
+ # Accumulate partial JSON for the current tool
+ tool_calls[current_tool_id]["input"] += chunk.delta.partial_json
+
+ elif chunk.type == "content_block_stop":
+ # End of a content block (could be text or tool)
+ current_tool_id = None
+
+ elif chunk.type == "message_delta":
+ if hasattr(chunk.delta, "stop_reason") and chunk.delta.stop_reason:
+ stop_reason = chunk.delta.stop_reason
+
+ # Get usage info if available
+ if hasattr(chunk, "usage") and hasattr(chunk.usage, "output_tokens"):
+ output_tokens = chunk.usage.output_tokens
+
+ elif chunk.type == "message_start":
+ if hasattr(chunk, "message") and hasattr(chunk.message, "usage"):
+ if hasattr(chunk.message.usage, "input_tokens"):
+ input_tokens = chunk.message.usage.input_tokens
+ if hasattr(chunk.message.usage, "output_tokens"):
+ output_tokens = chunk.message.usage.output_tokens
+
+ # Prepare the final response
+ usage = RequestUsage(
+ prompt_tokens=input_tokens,
+ completion_tokens=output_tokens,
+ )
+
+ # Determine content based on what was received
+ content: Union[str, List[FunctionCall]]
+ thought = None
+
+ if tool_calls:
+ # We received tool calls
+ if text_content:
+ # Text before tool calls is treated as thought
+ thought = "".join(text_content)
+
+ # Convert tool calls to FunctionCall objects
+ content = []
+ for _, tool_data in tool_calls.items():
+ # Parse the JSON input if needed
+ input_str = tool_data["input"]
+ try:
+ # If it's valid JSON, parse it; otherwise use as-is
+ if input_str.strip().startswith("{") and input_str.strip().endswith("}"):
+ parsed_input = json.loads(input_str)
+ input_str = json.dumps(parsed_input) # Re-serialize to ensure valid JSON
+ except json.JSONDecodeError:
+ # Keep as string if not valid JSON
+ pass
+
+ content.append(
+ FunctionCall(
+ id=tool_data["id"],
+ name=normalize_name(tool_data["name"]),
+ arguments=input_str,
+ )
+ )
+ else:
+ # Just text content
+ content = "".join(text_content)
+
+ # Create the final result
+ result = CreateResult(
+ finish_reason=normalize_stop_reason(stop_reason),
+ content=content,
+ usage=usage,
+ cached=False,
+ thought=thought,
+ )
+
+ # Update usage statistics
+ self._total_usage = _add_usage(self._total_usage, usage)
+ self._actual_usage = _add_usage(self._actual_usage, usage)
+
+ yield result
+
+ def count_tokens(self, messages: Sequence[LLMMessage], *, tools: Sequence[Tool | ToolSchema] = []) -> int:
+ """
+ Estimate the number of tokens used by messages and tools.
+
+ Note: This is an estimation based on common tokenization patterns and may not perfectly
+ match Anthropic's exact token counting for Claude models.
+ """
+ # Use cl100k_base encoding as an approximation for Claude's tokenizer
+ try:
+ encoding = tiktoken.get_encoding("cl100k_base")
+ except Exception:
+ encoding = tiktoken.get_encoding("gpt2") # Fallback
+
+ num_tokens = 0
+
+ # System message tokens (if any)
+ system_content = None
+ for message in messages:
+ if isinstance(message, SystemMessage):
+ system_content = message.content
+ break
+
+ if system_content:
+ num_tokens += len(encoding.encode(system_content)) + 15 # Approximate system message overhead
+
+ # Message tokens
+ for message in messages:
+ if isinstance(message, SystemMessage):
+ continue # Already counted
+
+ # Base token cost per message
+ num_tokens += 10 # Approximate message role & formatting overhead
+
+ # Content tokens
+ if isinstance(message, UserMessage) or isinstance(message, AssistantMessage):
+ if isinstance(message.content, str):
+ num_tokens += len(encoding.encode(message.content))
+ elif isinstance(message.content, list):
+ # Handle different content types
+ for part in message.content:
+ if isinstance(part, str):
+ num_tokens += len(encoding.encode(part))
+ elif isinstance(part, Image):
+ # Estimate vision tokens (simplified)
+ num_tokens += 512 # Rough estimation for image tokens
+ elif isinstance(part, FunctionCall):
+ num_tokens += len(encoding.encode(part.name))
+ num_tokens += len(encoding.encode(part.arguments))
+ num_tokens += 10 # Function call overhead
+ elif isinstance(message, FunctionExecutionResultMessage):
+ for result in message.content:
+ num_tokens += len(encoding.encode(result.content))
+ num_tokens += 10 # Function result overhead
+
+ # Tool tokens
+ for tool in tools:
+ if isinstance(tool, Tool):
+ tool_schema = tool.schema
+ else:
+ tool_schema = tool
+
+ # Name and description
+ num_tokens += len(encoding.encode(tool_schema["name"]))
+ if "description" in tool_schema:
+ num_tokens += len(encoding.encode(tool_schema["description"]))
+
+ # Parameters
+ if "parameters" in tool_schema:
+ params = tool_schema["parameters"]
+
+ if "properties" in params:
+ for prop_name, prop_schema in params["properties"].items():
+ num_tokens += len(encoding.encode(prop_name))
+
+ if "type" in prop_schema:
+ num_tokens += len(encoding.encode(prop_schema["type"]))
+
+ if "description" in prop_schema:
+ num_tokens += len(encoding.encode(prop_schema["description"]))
+
+ # Special handling for enums
+ if "enum" in prop_schema:
+ for value in prop_schema["enum"]:
+ if isinstance(value, str):
+ num_tokens += len(encoding.encode(value))
+ else:
+ num_tokens += 2 # Non-string enum values
+
+ # Tool overhead
+ num_tokens += 20
+
+ return num_tokens
+
+ def remaining_tokens(self, messages: Sequence[LLMMessage], *, tools: Sequence[Tool | ToolSchema] = []) -> int:
+ """Calculate the remaining tokens based on the model's token limit."""
+ token_limit = _model_info.get_token_limit(self._create_args["model"])
+ return token_limit - self.count_tokens(messages, tools=tools)
+
+ def actual_usage(self) -> RequestUsage:
+ return self._actual_usage
+
+ def total_usage(self) -> RequestUsage:
+ return self._total_usage
+
+ @property
+ def capabilities(self) -> ModelCapabilities: # type: ignore
+ warnings.warn("capabilities is deprecated, use model_info instead", DeprecationWarning, stacklevel=2)
+ return self._model_info
+
+ @property
+ def model_info(self) -> ModelInfo:
+ return self._model_info
+
+
+class AnthropicChatCompletionClient(
+ BaseAnthropicChatCompletionClient, Component[AnthropicClientConfigurationConfigModel]
+):
+ """
+ Chat completion client for Anthropic's Claude models.
+
+ Args:
+ model (str): The Claude model to use (e.g., "claude-3-sonnet-20240229", "claude-3-opus-20240229")
+ api_key (str, optional): Anthropic API key. Required if not in environment variables.
+ base_url (str, optional): Override the default API endpoint.
+ max_tokens (int, optional): Maximum tokens in the response. Default is 4096.
+ temperature (float, optional): Controls randomness. Lower is more deterministic. Default is 1.0.
+ top_p (float, optional): Controls diversity via nucleus sampling. Default is 1.0.
+ top_k (int, optional): Controls diversity via top-k sampling. Default is -1 (disabled).
+ model_info (ModelInfo, optional): The capabilities of the model. Required if using a custom model.
+
+ To use this client, you must install the Anthropic extension:
+
+ .. code-block:: bash
+
+ pip install "autogen-ext[anthropic]"
+
+ Example:
+
+ .. code-block:: python
+
+ from autogen_ext.models.anthropic import AnthropicChatCompletionClient
+ from autogen_core.models import UserMessage
+
+ anthropic_client = AnthropicChatCompletionClient(
+ model="claude-3-sonnet-20240229",
+ api_key="your-api-key", # Optional if ANTHROPIC_API_KEY is set in environment
+ )
+
+ result = await anthropic_client.create([UserMessage(content="What is the capital of France?", source="user")])
+ print(result)
+
+ To load the client from a configuration:
+
+ .. code-block:: python
+
+ from autogen_core.models import ChatCompletionClient
+
+ config = {
+ "provider": "AnthropicChatCompletionClient",
+ "config": {"model": "claude-3-sonnet-20240229"},
+ }
+
+ client = ChatCompletionClient.load_component(config)
+
+ The client supports function calling with Claude models that have the capability:
+
+ .. code-block:: python
+
+ from autogen_core.tools import FunctionTool
+
+
+ def get_weather(location: str) -> str:
+ '''Get the weather for a location'''
+ return f"The weather in {location} is sunny."
+
+
+ tool = FunctionTool(get_weather)
+
+ result = await anthropic_client.create(
+ [UserMessage(content="What's the weather in Paris?", source="user")],
+ tools=[tool],
+ )
+ """
+
+ component_type = "model"
+ component_config_schema = AnthropicClientConfigurationConfigModel
+ component_provider_override = "autogen_ext.models.anthropic.AnthropicChatCompletionClient"
+
+ def __init__(self, **kwargs: Unpack[AnthropicClientConfiguration]):
+ if "model" not in kwargs:
+ raise ValueError("model is required for AnthropicChatCompletionClient")
+
+ self._raw_config: Dict[str, Any] = dict(kwargs).copy()
+ copied_args = dict(kwargs).copy()
+
+ model_info: Optional[ModelInfo] = None
+ if "model_info" in kwargs:
+ model_info = kwargs["model_info"]
+ del copied_args["model_info"]
+
+ client = _anthropic_client_from_config(copied_args)
+ create_args = _create_args_from_config(copied_args)
+
+ super().__init__(
+ client=client,
+ create_args=create_args,
+ model_info=model_info,
+ )
+
+ def __getstate__(self) -> Dict[str, Any]:
+ state = self.__dict__.copy()
+ state["_client"] = None
+ return state
+
+ def __setstate__(self, state: Dict[str, Any]) -> None:
+ self.__dict__.update(state)
+ self._client = _anthropic_client_from_config(state["_raw_config"])
+
+ def _to_config(self) -> AnthropicClientConfigurationConfigModel:
+ copied_config = self._raw_config.copy()
+ return AnthropicClientConfigurationConfigModel(**copied_config)
+
+ @classmethod
+ def _from_config(cls, config: AnthropicClientConfigurationConfigModel) -> Self:
+ copied_config = config.model_copy().model_dump(exclude_none=True)
+ return cls(**copied_config)
diff --git a/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_model_info.py b/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_model_info.py
new file mode 100644
index 000000000..a945b7c9f
--- /dev/null
+++ b/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_model_info.py
@@ -0,0 +1,113 @@
+from typing import Dict
+
+from autogen_core.models import ModelFamily, ModelInfo
+
+# Mapping of model names to their capabilities
+# For Anthropic's Claude models based on:
+# https://docs.anthropic.com/claude/docs/models-overview
+_MODEL_INFO: Dict[str, ModelInfo] = {
+ # Claude 3.7 Sonnet
+ "claude-3-7-sonnet-20250219": {
+ "vision": True,
+ "function_calling": True,
+ "json_output": True,
+ "family": ModelFamily.CLAUDE_3_7_SONNET,
+ },
+ # Claude 3.7 Sonnet latest alias
+ "claude-3-7-sonnet-latest": {
+ "vision": True,
+ "function_calling": True,
+ "json_output": True,
+ "family": ModelFamily.CLAUDE_3_7_SONNET,
+ },
+ # Claude 3 Opus (most powerful)
+ "claude-3-opus-20240229": {
+ "vision": True,
+ "function_calling": True,
+ "json_output": True,
+ "family": ModelFamily.CLAUDE_3_5_SONNET,
+ },
+ # Claude 3 Sonnet (balanced)
+ "claude-3-sonnet-20240229": {
+ "vision": True,
+ "function_calling": True,
+ "json_output": True,
+ "family": ModelFamily.CLAUDE_3_5_SONNET,
+ },
+ # Claude 3 Haiku (fastest)
+ "claude-3-haiku-20240307": {
+ "vision": True,
+ "function_calling": True,
+ "json_output": True,
+ "family": ModelFamily.CLAUDE_3_5_SONNET,
+ },
+ # Claude 3.5 Sonnet
+ "claude-3-5-sonnet-20240620": {
+ "vision": True,
+ "function_calling": True,
+ "json_output": True,
+ "family": ModelFamily.CLAUDE_3_5_SONNET,
+ },
+ # Claude Instant v1 (legacy)
+ "claude-instant-1.2": {
+ "vision": False,
+ "function_calling": False,
+ "json_output": True,
+ "family": ModelFamily.CLAUDE_3_5_SONNET,
+ },
+ # Claude 2 (legacy)
+ "claude-2.0": {
+ "vision": False,
+ "function_calling": False,
+ "json_output": True,
+ "family": ModelFamily.CLAUDE_3_5_SONNET,
+ },
+ # Claude 2.1 (legacy)
+ "claude-2.1": {
+ "vision": False,
+ "function_calling": False,
+ "json_output": True,
+ "family": ModelFamily.CLAUDE_3_5_SONNET,
+ },
+}
+
+# Model token limits (context window size)
+_MODEL_TOKEN_LIMITS: Dict[str, int] = {
+ "claude-3-opus-20240229": 200000,
+ "claude-3-sonnet-20240229": 200000,
+ "claude-3-haiku-20240307": 200000,
+ "claude-3-5-sonnet-20240620": 200000,
+ "claude-3-7-sonnet-20250219": 200000,
+ "claude-instant-1.2": 100000,
+ "claude-2.0": 100000,
+ "claude-2.1": 200000,
+}
+
+
+def get_info(model: str) -> ModelInfo:
+ """Get the model information for a specific model."""
+ # Check for exact match first
+ if model in _MODEL_INFO:
+ return _MODEL_INFO[model]
+
+ # Check for partial match (for handling model variants)
+ for model_id in _MODEL_INFO:
+ if model.startswith(model_id.split("-2")[0]): # Match base name
+ return _MODEL_INFO[model_id]
+
+ raise KeyError(f"Model '{model}' not found in model info")
+
+
+def get_token_limit(model: str) -> int:
+ """Get the token limit for a specific model."""
+ # Check for exact match first
+ if model in _MODEL_TOKEN_LIMITS:
+ return _MODEL_TOKEN_LIMITS[model]
+
+ # Check for partial match (for handling model variants)
+ for model_id in _MODEL_TOKEN_LIMITS:
+ if model.startswith(model_id.split("-2")[0]): # Match base name
+ return _MODEL_TOKEN_LIMITS[model_id]
+
+ # Default to a reasonable limit if model not found
+ return 100000
diff --git a/python/packages/autogen-ext/src/autogen_ext/models/anthropic/config/__init__.py b/python/packages/autogen-ext/src/autogen_ext/models/anthropic/config/__init__.py
new file mode 100644
index 000000000..58ff24848
--- /dev/null
+++ b/python/packages/autogen-ext/src/autogen_ext/models/anthropic/config/__init__.py
@@ -0,0 +1,63 @@
+from typing import Any, Dict, List, Literal, Optional, Union
+
+from autogen_core.models import ModelCapabilities, ModelInfo # type: ignore
+from pydantic import BaseModel
+from typing_extensions import TypedDict
+
+
+class ResponseFormat(TypedDict):
+ type: Literal["text", "json_object"]
+
+
+class CreateArguments(TypedDict, total=False):
+ model: str
+ max_tokens: Optional[int]
+ temperature: Optional[float]
+ top_p: Optional[float]
+ top_k: Optional[int]
+ stop_sequences: Optional[List[str]]
+ response_format: Optional[ResponseFormat]
+ metadata: Optional[Dict[str, str]]
+
+
+class BaseAnthropicClientConfiguration(CreateArguments, total=False):
+ api_key: str
+ base_url: Optional[str]
+ model_capabilities: ModelCapabilities # type: ignore
+ model_info: ModelInfo
+ """What functionality the model supports, determined by default from model name but is overridden if value passed."""
+ timeout: Optional[float]
+ max_retries: Optional[int]
+ default_headers: Optional[Dict[str, str]]
+
+
+class AnthropicClientConfiguration(BaseAnthropicClientConfiguration, total=False):
+ tools: Optional[List[Dict[str, Any]]]
+ tool_choice: Optional[Union[Literal["auto", "any", "none"], Dict[str, Any]]]
+
+
+# Pydantic equivalents of the above TypedDicts
+class CreateArgumentsConfigModel(BaseModel):
+ model: str
+ max_tokens: int | None = 4096
+ temperature: float | None = 1.0
+ top_p: float | None = None
+ top_k: int | None = None
+ stop_sequences: List[str] | None = None
+ response_format: ResponseFormat | None = None
+ metadata: Dict[str, str] | None = None
+
+
+class BaseAnthropicClientConfigurationConfigModel(CreateArgumentsConfigModel):
+ api_key: str | None = None
+ base_url: str | None = None
+ model_capabilities: ModelCapabilities | None = None # type: ignore
+ model_info: ModelInfo | None = None
+ timeout: float | None = None
+ max_retries: int | None = None
+ default_headers: Dict[str, str] | None = None
+
+
+class AnthropicClientConfigurationConfigModel(BaseAnthropicClientConfigurationConfigModel):
+ tools: List[Dict[str, Any]] | None = None
+ tool_choice: Union[Literal["auto", "any", "none"], Dict[str, Any]] | None = None
diff --git a/python/packages/autogen-ext/tests/models/test_anthropic_model_client.py b/python/packages/autogen-ext/tests/models/test_anthropic_model_client.py
new file mode 100644
index 000000000..cdb53a55b
--- /dev/null
+++ b/python/packages/autogen-ext/tests/models/test_anthropic_model_client.py
@@ -0,0 +1,301 @@
+import asyncio
+import os
+from typing import List, Sequence
+
+import pytest
+from autogen_core import CancellationToken, FunctionCall
+from autogen_core.models import (
+ AssistantMessage,
+ CreateResult,
+ FunctionExecutionResult,
+ FunctionExecutionResultMessage,
+ SystemMessage,
+ UserMessage,
+)
+from autogen_core.models._types import LLMMessage
+from autogen_core.tools import FunctionTool
+from autogen_ext.models.anthropic import AnthropicChatCompletionClient
+
+
+def _pass_function(input: str) -> str:
+ """Simple passthrough function."""
+ return f"Processed: {input}"
+
+
+def _add_numbers(a: int, b: int) -> int:
+ """Add two numbers together."""
+ return a + b
+
+
+async def test_anthropic_basic_completion() -> None:
+ """Test basic message completion with Claude."""
+ api_key = os.getenv("ANTHROPIC_API_KEY")
+ if not api_key:
+ pytest.skip("ANTHROPIC_API_KEY not found in environment variables")
+
+ client = AnthropicChatCompletionClient(
+ model="claude-3-haiku-20240307", # Use haiku for faster/cheaper testing
+ api_key=api_key,
+ temperature=0.0, # Added temperature param to test
+ stop_sequences=["STOP"], # Added stop sequence
+ )
+
+ # Test basic completion
+ result = await client.create(
+ messages=[
+ SystemMessage(content="You are a helpful assistant."),
+ UserMessage(content="What's 2+2? Answer with just the number.", source="user"),
+ ]
+ )
+
+ assert isinstance(result.content, str)
+ assert "4" in result.content
+ assert result.finish_reason == "stop"
+
+ # Test JSON output - add to existing test
+ json_result = await client.create(
+ messages=[
+ UserMessage(content="Return a JSON with key 'value' set to 42", source="user"),
+ ],
+ json_output=True,
+ )
+ assert isinstance(json_result.content, str)
+ assert "42" in json_result.content
+
+ # Check usage tracking
+ usage = client.total_usage()
+ assert usage.prompt_tokens > 0
+ assert usage.completion_tokens > 0
+
+
+async def test_anthropic_streaming() -> None:
+ """Test streaming capabilities with Claude."""
+ api_key = os.getenv("ANTHROPIC_API_KEY")
+ if not api_key:
+ pytest.skip("ANTHROPIC_API_KEY not found in environment variables")
+
+ client = AnthropicChatCompletionClient(
+ model="claude-3-haiku-20240307",
+ api_key=api_key,
+ )
+
+ # Test streaming completion
+ chunks: List[str | CreateResult] = []
+ async for chunk in client.create_stream(
+ messages=[
+ UserMessage(content="Count from 1 to 5. Each number on its own line.", source="user"),
+ ]
+ ):
+ chunks.append(chunk)
+
+ # Verify we got multiple chunks
+ assert len(chunks) > 1
+
+ # Check final result
+ final_result = chunks[-1]
+ assert isinstance(final_result, CreateResult)
+ assert final_result.finish_reason == "stop"
+
+ # Check content contains numbers 1-5
+ assert isinstance(final_result.content, str)
+ combined_content = final_result.content
+ for i in range(1, 6):
+ assert str(i) in combined_content
+
+
+async def test_anthropic_tool_calling() -> None:
+ """Test tool calling capabilities with Claude."""
+ api_key = os.getenv("ANTHROPIC_API_KEY")
+ if not api_key:
+ pytest.skip("ANTHROPIC_API_KEY not found in environment variables")
+
+ client = AnthropicChatCompletionClient(
+ model="claude-3-haiku-20240307",
+ api_key=api_key,
+ )
+
+ # Define tools
+ pass_tool = FunctionTool(_pass_function, description="Process input text", name="process_text")
+ add_tool = FunctionTool(_add_numbers, description="Add two numbers together", name="add_numbers")
+
+ # Test tool calling with instruction to use specific tool
+ messages: List[LLMMessage] = [
+ SystemMessage(content="Use the tools available to help the user."),
+ UserMessage(content="Process the text 'hello world' using the process_text tool.", source="user"),
+ ]
+
+ result = await client.create(messages=messages, tools=[pass_tool, add_tool])
+
+ # Check that we got a tool call
+ assert isinstance(result.content, list)
+ assert len(result.content) >= 1
+ assert isinstance(result.content[0], FunctionCall)
+
+ # Check that the correct tool was called
+ function_call = result.content[0]
+ assert function_call.name == "process_text"
+
+ # Test tool response handling
+ messages.append(AssistantMessage(content=result.content, source="assistant"))
+ messages.append(
+ FunctionExecutionResultMessage(
+ content=[
+ FunctionExecutionResult(content="Processed: hello world", call_id=result.content[0].id, is_error=False)
+ ]
+ )
+ )
+
+ # Get response after tool execution
+ after_tool_result = await client.create(messages=messages)
+
+ # Check we got a text response
+ assert isinstance(after_tool_result.content, str)
+
+ # Test multiple tool use
+ multi_tool_prompt: List[LLMMessage] = [
+ SystemMessage(content="Use the tools as needed to help the user."),
+ UserMessage(content="First process the text 'test' and then add 2 and 3.", source="user"),
+ ]
+
+ multi_tool_result = await client.create(messages=multi_tool_prompt, tools=[pass_tool, add_tool])
+
+ # We just need to verify we get at least one tool call
+ assert isinstance(multi_tool_result.content, list)
+ assert len(multi_tool_result.content) > 0
+ assert isinstance(multi_tool_result.content[0], FunctionCall)
+
+
+async def test_anthropic_token_counting() -> None:
+ """Test token counting functionality."""
+ api_key = os.getenv("ANTHROPIC_API_KEY")
+ if not api_key:
+ pytest.skip("ANTHROPIC_API_KEY not found in environment variables")
+
+ client = AnthropicChatCompletionClient(
+ model="claude-3-haiku-20240307",
+ api_key=api_key,
+ )
+
+ messages: Sequence[LLMMessage] = [
+ SystemMessage(content="You are a helpful assistant."),
+ UserMessage(content="Hello, how are you?", source="user"),
+ ]
+
+ # Test token counting
+ num_tokens = client.count_tokens(messages)
+ assert num_tokens > 0
+
+ # Test remaining token calculation
+ remaining = client.remaining_tokens(messages)
+ assert remaining > 0
+ assert remaining < 200000 # Claude's max context
+
+ # Test token counting with tools
+ tools = [
+ FunctionTool(_pass_function, description="Process input text", name="process_text"),
+ FunctionTool(_add_numbers, description="Add two numbers together", name="add_numbers"),
+ ]
+ tokens_with_tools = client.count_tokens(messages, tools=tools)
+ assert tokens_with_tools > num_tokens # Should be more tokens with tools
+
+
+async def test_anthropic_cancellation() -> None:
+ """Test cancellation of requests."""
+ api_key = os.getenv("ANTHROPIC_API_KEY")
+ if not api_key:
+ pytest.skip("ANTHROPIC_API_KEY not found in environment variables")
+
+ client = AnthropicChatCompletionClient(
+ model="claude-3-haiku-20240307",
+ api_key=api_key,
+ )
+
+ # Create a cancellation token
+ cancellation_token = CancellationToken()
+
+ # Schedule cancellation after a short delay
+ async def cancel_after_delay() -> None:
+ await asyncio.sleep(0.5) # Short delay
+ cancellation_token.cancel()
+
+ # Start task to cancel request
+ asyncio.create_task(cancel_after_delay())
+
+ # Create a request with long output
+ with pytest.raises(asyncio.CancelledError):
+ await client.create(
+ messages=[
+ UserMessage(content="Write a detailed 5-page essay on the history of computing.", source="user"),
+ ],
+ cancellation_token=cancellation_token,
+ )
+
+
+async def test_anthropic_multimodal() -> None:
+ """Test multimodal capabilities with Claude."""
+ api_key = os.getenv("ANTHROPIC_API_KEY")
+ if not api_key:
+ pytest.skip("ANTHROPIC_API_KEY not found in environment variables")
+
+ # Skip if PIL is not available
+ try:
+ from autogen_core import Image
+ from PIL import Image as PILImage
+ except ImportError:
+ pytest.skip("PIL or other dependencies not installed")
+
+ client = AnthropicChatCompletionClient(
+ model="claude-3-5-sonnet-latest", # Use a model that supports vision
+ api_key=api_key,
+ )
+
+ # Use a simple test image that's reliable
+ # 1. Create a simple colored square image
+ width, height = 100, 100
+ color = (255, 0, 0) # Red
+ pil_image = PILImage.new("RGB", (width, height), color)
+
+ # 2. Convert to autogen_core Image format
+ img = Image(pil_image)
+
+ # Test multimodal message
+ result = await client.create(
+ messages=[
+ UserMessage(content=["What color is this square? Answer in one word.", img], source="user"),
+ ]
+ )
+
+ # Verify we got a response describing the image
+ assert isinstance(result.content, str)
+ assert len(result.content) > 0
+ assert "red" in result.content.lower()
+ assert result.finish_reason == "stop"
+
+
+async def test_anthropic_serialization() -> None:
+ """Test serialization and deserialization of component."""
+
+ api_key = os.getenv("ANTHROPIC_API_KEY")
+ if not api_key:
+ pytest.skip("ANTHROPIC_API_KEY not found in environment variables")
+
+ client = AnthropicChatCompletionClient(
+ model="claude-3-haiku-20240307",
+ api_key=api_key,
+ )
+
+ # Serialize and deserialize
+ model_client_config = client.dump_component()
+ assert model_client_config is not None
+ assert model_client_config.config is not None
+
+ loaded_model_client = AnthropicChatCompletionClient.load_component(model_client_config)
+ assert loaded_model_client is not None
+ assert isinstance(loaded_model_client, AnthropicChatCompletionClient)
diff --git a/python/packages/autogen-studio/autogenstudio/teammanager/teammanager.py b/python/packages/autogen-studio/autogenstudio/teammanager/teammanager.py
index c8b4f481b..03b1ca48c 100644
--- a/python/packages/autogen-studio/autogenstudio/teammanager/teammanager.py
+++ b/python/packages/autogen-studio/autogenstudio/teammanager/teammanager.py
@@ -127,7 +127,6 @@ class TeamManager:
while not llm_event_logger.events.empty():
event = await llm_event_logger.events.get()
yield event
-
finally:
# Cleanup - remove our handler
logger.handlers.remove(llm_event_logger)
diff --git a/python/packages/autogen-studio/frontend/src/components/types/datamodel.ts b/python/packages/autogen-studio/frontend/src/components/types/datamodel.ts
index 19925902a..027188d11 100644
--- a/python/packages/autogen-studio/frontend/src/components/types/datamodel.ts
+++ b/python/packages/autogen-studio/frontend/src/components/types/datamodel.ts
@@ -196,6 +196,29 @@ export interface AzureOpenAIClientConfig extends BaseOpenAIClientConfig {
azure_ad_token_provider?: Component<any>;
}
+export interface BaseAnthropicClientConfig extends CreateArgumentsConfig {
+ model: string;
+ api_key?: string;
+ base_url?: string;
+ model_capabilities?: any; // ModelCapabilities equivalent
+ model_info?: ModelInfo;
+ timeout?: number;
+ max_retries?: number;
+ default_headers?: Record<string, string>;
+ max_tokens?: number;
+ temperature?: number;
+ top_p?: number;
+ top_k?: number;
+ stop_sequences?: string | string[];
+ response_format?: any; // ResponseFormat equivalent
+ metadata?: Record<string, string>;
+}
+
+export interface AnthropicClientConfig extends BaseAnthropicClientConfig {
+ tools?: Array<Record<string, any>>;
+ tool_choice?: "auto" | "any" | "none" | Record<string, any>;
+}
+
export interface UnboundedChatCompletionContextConfig {
// Empty in example but could have props
}
@@ -220,7 +243,10 @@ export type AgentConfig =
| AssistantAgentConfig
| UserProxyAgentConfig;
-export type ModelConfig = OpenAIClientConfig | AzureOpenAIClientConfig;
+export type ModelConfig =
+ | OpenAIClientConfig
+ | AzureOpenAIClientConfig
+ | AnthropicClientConfig;
export type ToolConfig = FunctionToolConfig;
diff --git a/python/packages/autogen-studio/frontend/src/components/types/guards.ts b/python/packages/autogen-studio/frontend/src/components/types/guards.ts
index 726a40a35..476547457 100644
--- a/python/packages/autogen-studio/frontend/src/components/types/guards.ts
+++ b/python/packages/autogen-studio/frontend/src/components/types/guards.ts
@@ -19,6 +19,7 @@ import type {
MaxMessageTerminationConfig,
TextMentionTerminationConfig,
UnboundedChatCompletionContextConfig,
+ AnthropicClientConfig,
} from "./datamodel";
// Provider constants
@@ -35,6 +36,7 @@ const PROVIDERS = {
// Models
OPENAI: "autogen_ext.models.openai.OpenAIChatCompletionClient",
AZURE_OPENAI: "autogen_ext.models.openai.AzureOpenAIChatCompletionClient",
+ ANTHROPIC: "autogen_ext.models.anthropic.AnthropicChatCompletionClient",
// Tools
FUNCTION_TOOL: "autogen_core.tools.FunctionTool",
@@ -56,6 +58,7 @@ type ProviderToConfig = {
// Teams
[PROVIDERS.SELECTOR_TEAM]: SelectorGroupChatConfig;
[PROVIDERS.ROUND_ROBIN_TEAM]: RoundRobinGroupChatConfig;
+ [PROVIDERS.ANTHROPIC]: AnthropicClientConfig;
// Agents
[PROVIDERS.ASSISTANT_AGENT]: AssistantAgentConfig;
@@ -181,6 +184,11 @@ export function isAzureOpenAIModel(
): component is Component<AzureOpenAIClientConfig> {
return isComponentOfType(component, PROVIDERS.AZURE_OPENAI);
}
+export function isAnthropicModel(
+ component: Component<ComponentConfig>
+): component is Component<AnthropicClientConfig> {
+ return component.provider === PROVIDERS.ANTHROPIC;
+}
// Tool provider guards with proper type narrowing
export function isFunctionTool(
diff --git a/python/packages/autogen-studio/frontend/src/components/views/gallery/detail.tsx b/python/packages/autogen-studio/frontend/src/components/views/gallery/detail.tsx
index b37232131..af219d600 100644
--- a/python/packages/autogen-studio/frontend/src/components/views/gallery/detail.tsx
+++ b/python/packages/autogen-studio/frontend/src/components/views/gallery/detail.tsx
@@ -13,7 +13,7 @@ import {
Trash,
Plus,
} from "lucide-react";
-import { ComponentEditor } from "../team/builder/component-editor/component-editor";
+import { ComponentEditor } from "../teambuilder/builder/component-editor/component-editor";
import { TruncatableText } from "../atoms";
import {
Component,
diff --git a/python/packages/autogen-studio/frontend/src/components/views/playground/chat/chat.tsx b/python/packages/autogen-studio/frontend/src/components/views/playground/chat/chat.tsx
index a9f1583f7..ce2127ae2 100644
--- a/python/packages/autogen-studio/frontend/src/components/views/playground/chat/chat.tsx
+++ b/python/packages/autogen-studio/frontend/src/components/views/playground/chat/chat.tsx
@@ -16,7 +16,7 @@ import {
} from "../../../types/datamodel";
import { appContext } from "../../../../hooks/provider";
import ChatInput from "./chatinput";
-import { teamAPI } from "../../team/api";
+import { teamAPI } from "../../teambuilder/api";
import { sessionAPI } from "../api";
import RunView from "./runview";
import { TIMEOUT_CONFIG } from "./types";
diff --git a/python/packages/autogen-studio/frontend/src/components/views/playground/chat/logrenderer.tsx b/python/packages/autogen-studio/frontend/src/components/views/playground/chat/logrenderer.tsx
index f4a3a1476..d4f3d61aa 100644
--- a/python/packages/autogen-studio/frontend/src/components/views/playground/chat/logrenderer.tsx
+++ b/python/packages/autogen-studio/frontend/src/components/views/playground/chat/logrenderer.tsx
@@ -95,15 +95,17 @@ const FullLogView = ({
))}
</div>
- <div className="space-y-2">
- <h4 className="text-sm font-medium">Response</h4>
- <div className="p-4 bg-tertiary rounded-lg">
- <TruncatableText
- content={event.response.choices[0]?.message.content}
- textThreshold={1000}
- />
+ {event.response.choices && (
+ <div className="space-y-2">
+ <h4 className="text-sm font-medium">Response</h4>
+ <div className="p-4 bg-tertiary rounded-lg">
+ <TruncatableText
+ content={event.response?.choices[0]?.message.content}
+ textThreshold={1000}
+ />
+ </div>
</div>
- </div>
+ )}
<div className="grid grid-cols-2 md:grid-cols-4 gap-4 mt-4">
<div className="p-3 bg-tertiary rounded-lg">
@@ -162,6 +164,8 @@ const LLMLogRenderer: React.FC<LLMLogRendererProps> = ({ content }) => {
const totalTokens = response.usage.total_tokens;
const shortAgentId = agent_id ? `${agent_id.split("/")[0]}` : "";
+ console.log("log event full", content);
+
return (
<>
<div className="flex items-center gap-2 py-2 bg-secondary/20 rounded-lg text-sm text-secondary hover:text-primary transition-colors group">
diff --git a/python/packages/autogen-studio/frontend/src/components/views/playground/editor.tsx b/python/packages/autogen-studio/frontend/src/components/views/playground/editor.tsx
index e49ee7168..ba61c1d3e 100644
--- a/python/packages/autogen-studio/frontend/src/components/views/playground/editor.tsx
+++ b/python/packages/autogen-studio/frontend/src/components/views/playground/editor.tsx
@@ -4,7 +4,7 @@ import { TriangleAlertIcon } from "lucide-react";
import type { FormProps } from "antd";
import { SessionEditorProps } from "./types";
import { Team } from "../../types/datamodel";
-import { teamAPI } from "../team/api";
+import { teamAPI } from "../teambuilder/api";
import { appContext } from "../../../hooks/provider";
import { Link } from "gatsby";
diff --git a/python/packages/autogen-studio/frontend/src/components/views/playground/manager.tsx b/python/packages/autogen-studio/frontend/src/components/views/playground/manager.tsx
index 907fd4003..e2b33152b 100644
--- a/python/packages/autogen-studio/frontend/src/components/views/playground/manager.tsx
+++ b/python/packages/autogen-studio/frontend/src/components/views/playground/manager.tsx
@@ -7,7 +7,7 @@ import { SessionEditor } from "./editor";
import type { Session, Team } from "../../types/datamodel";
import ChatView from "./chat/chat";
import { Sidebar } from "./sidebar";
-import { teamAPI } from "../team/api";
+import { teamAPI } from "../teambuilder/api";
import { useGalleryStore } from "../gallery/store";
export const SessionManager: React.FC = () => {
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/fields/model-fields.tsx b/python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/fields/model-fields.tsx
deleted file mode 100644
index 5af067cfc..000000000
--- a/python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/fields/model-fields.tsx
+++ /dev/null
@@ -1,350 +0,0 @@
-import React, { useCallback } from "react";
-import { Input, InputNumber, Select, Tooltip } from "antd";
-import { HelpCircle } from "lucide-react";
-import {
- Component,
- ComponentConfig,
- ModelConfig,
-} from "../../../../../types/datamodel";
-import { isOpenAIModel, isAzureOpenAIModel } from "../../../../../types/guards";
-import DetailGroup from "../detailgroup";
-import TextArea from "antd/es/input/TextArea";
-// import DetailGroup from "./detail-group";
-
-interface ModelFieldsProps {
- component: Component<ModelConfig>;
- onChange: (updates: Partial<Component<ComponentConfig>>) => void;
-}
-
-const InputWithTooltip: React.FC<{
- label: string;
- tooltip: string;
- children: React.ReactNode;
-}> = ({ label, tooltip, children }) => (
- <label className="block">
- <div className="flex items-center gap-2 mb-1">
- <span className="text-sm font-medium text-primary">{label}</span>
- <Tooltip title={tooltip}>
- <HelpCircle className="w-4 h-4 text-secondary" />
- </Tooltip>
- </div>
- {children}
- </label>
-);
-
-export const ModelFields: React.FC<ModelFieldsProps> = ({
- component,
- onChange,
-}) => {
- if (!isOpenAIModel(component) && !isAzureOpenAIModel(component)) return null;
-
- const handleComponentUpdate = useCallback(
- (updates: Partial<Component<ComponentConfig>>) => {
- onChange({
- ...component,
- ...updates,
- config: {
- ...component.config,
- ...(updates.config || {}),
- },
- });
- },
- [component, onChange]
- );
-
- const handleConfigUpdate = useCallback(
- (field: string, value: unknown) => {
- handleComponentUpdate({
- config: {
- ...component.config,
- [field]: value,
- },
- });
- },
- [component, handleComponentUpdate]
- );
-
- // Common arguments fields shared between OpenAI and Azure OpenAI models
- const ArgumentsFields = () => (
- <div className="space-y-4">
- <InputWithTooltip
- label="Temperature"
- tooltip="Controls randomness in the model's output. Higher values (e.g., 0.8) make output more random, lower values (e.g., 0.2) make it more focused."
- >
- <InputNumber
- min={0}
- max={2}
- step={0.1}
- value={component.config.temperature}
- onChange={(value) => handleConfigUpdate("temperature", value)}
- className="w-full"
- />
- </InputWithTooltip>
-
- <InputWithTooltip
- label="Max Tokens"
- tooltip="Maximum length of the model's output in tokens"
- >
- <InputNumber
- min={1}
- value={component.config.max_tokens}
- onChange={(value) => handleConfigUpdate("max_tokens", value)}
- className="w-full"
- />
- </InputWithTooltip>
-
- <InputWithTooltip
- label="Top P"
- tooltip="Controls diversity via nucleus sampling. Lower values (e.g., 0.1) make output more focused, higher values (e.g., 0.9) make it more diverse."
- >
- <InputNumber
- min={0}
- max={1}
- step={0.1}
- value={component.config.top_p}
- onChange={(value) => handleConfigUpdate("top_p", value)}
- className="w-full"
- />
- </InputWithTooltip>
-
- <InputWithTooltip
- label="Frequency Penalty"
- tooltip="Decreases the model's likelihood to repeat the same information. Values range from -2.0 to 2.0."
- >
- <InputNumber
- min={-2}
- max={2}
- step={0.1}
- value={component.config.frequency_penalty}
- onChange={(value) => handleConfigUpdate("frequency_penalty", value)}
- className="w-full"
- />
- </InputWithTooltip>
-
- <InputWithTooltip
- label="Presence Penalty"
- tooltip="Increases the model's likelihood to talk about new topics. Values range from -2.0 to 2.0."
- >
- <InputNumber
- min={-2}
- max={2}
- step={0.1}
- value={component.config.presence_penalty}
- onChange={(value) => handleConfigUpdate("presence_penalty", value)}
- className="w-full"
- />
- </InputWithTooltip>
-
- <InputWithTooltip
- label="Stop Sequences"
- tooltip="Sequences where the model will stop generating further tokens"
- >
- <Select
- mode="tags"
- value={component.config.stop as string[]}
- onChange={(value) => handleConfigUpdate("stop", value)}
- placeholder="Enter stop sequences"
- className="w-full"
- />
- </InputWithTooltip>
- </div>
- );
-
- if (isOpenAIModel(component)) {
- return (
- <div className="space-y-6">
- <DetailGroup title="Component Details">
- <div className="space-y-4">
- <label className="block">
- <span className="text-sm font-medium text-primary">Name</span>
- <Input
- value={component.label || ""}
- onChange={(e) =>
- handleComponentUpdate({ label: e.target.value })
- }
- placeholder="Team name"
- className="mt-1"
- />
- </label>
-
- <label className="block">
- <span className="text-sm font-medium text-primary">
- Description
- </span>
- <TextArea
- value={component.description || ""}
- onChange={(e) =>
- handleComponentUpdate({ description: e.target.value })
- }
- placeholder="Team description"
- rows={4}
- className="mt-1"
- />
- </label>
- </div>
- </DetailGroup>
-
- <DetailGroup title="Model Configuration">
- <div className="space-y-4">
- <InputWithTooltip
- label="Model"
- tooltip="The name of the OpenAI model to use (e.g., gpt-4, gpt-3.5-turbo)"
- >
- <Input
- value={component.config.model}
- onChange={(e) => handleConfigUpdate("model", e.target.value)}
- required
- />
- </InputWithTooltip>
-
- <InputWithTooltip label="API Key" tooltip="Your OpenAI API key">
- <Input.Password
- value={component.config.api_key}
- onChange={(e) => handleConfigUpdate("api_key", e.target.value)}
- />
- </InputWithTooltip>
-
- <InputWithTooltip
- label="Organization"
- tooltip="Optional: Your OpenAI organization ID"
- >
- <Input
- value={component.config.organization}
- onChange={(e) =>
- handleConfigUpdate("organization", e.target.value)
- }
- />
- </InputWithTooltip>
-
- <InputWithTooltip
- label="Base URL"
- tooltip="Optional: Custom base URL for API requests"
- >
- <Input
- value={component.config.base_url}
- onChange={(e) => handleConfigUpdate("base_url", e.target.value)}
- />
- </InputWithTooltip>
-
- <InputWithTooltip
- label="Timeout"
- tooltip="Request timeout in seconds"
- >
- <InputNumber
- min={1}
- value={component.config.timeout}
- onChange={(value) => handleConfigUpdate("timeout", value)}
- className="w-full"
- />
- </InputWithTooltip>
-
- <InputWithTooltip
- label="Max Retries"
- tooltip="Maximum number of retry attempts for failed requests"
- >
- <InputNumber
- min={0}
- value={component.config.max_retries}
- onChange={(value) => handleConfigUpdate("max_retries", value)}
- className="w-full"
- />
- </InputWithTooltip>
- </div>
- </DetailGroup>
-
- <DetailGroup title="Model Parameters">
- <ArgumentsFields />
- </DetailGroup>
- </div>
- );
- }
-
- if (isAzureOpenAIModel(component)) {
- return (
- <div className="space-y-6">
- <DetailGroup title="Azure Configuration">
- <div className="space-y-4">
- <InputWithTooltip
- label="Model"
- tooltip="The name of the Azure OpenAI model deployment"
- >
- <Input
- value={component.config.model}
- onChange={(e) => handleConfigUpdate("model", e.target.value)}
- required
- />
- </InputWithTooltip>
-
- <InputWithTooltip
- label="Azure Endpoint"
- tooltip="Your Azure OpenAI service endpoint URL"
- >
- <Input
- value={component.config.azure_endpoint}
- onChange={(e) =>
- handleConfigUpdate("azure_endpoint", e.target.value)
- }
- required
- />
- </InputWithTooltip>
-
- <InputWithTooltip
- label="API Key"
- tooltip="Your Azure OpenAI API key"
- >
- <Input.Password
- value={component.config.api_key}
- onChange={(e) => handleConfigUpdate("api_key", e.target.value)}
- />
- </InputWithTooltip>
-
- <InputWithTooltip
- label="Azure Deployment"
- tooltip="The name of your Azure OpenAI model deployment"
- >
- <Input
- value={component.config.azure_deployment}
- onChange={(e) =>
- handleConfigUpdate("azure_deployment", e.target.value)
- }
- />
- </InputWithTooltip>
-
- <InputWithTooltip
- label="API Version"
- tooltip="Azure OpenAI API version (e.g., 2023-05-15)"
- >
- <Input
- value={component.config.api_version}
- onChange={(e) =>
- handleConfigUpdate("api_version", e.target.value)
- }
- required
- />
- </InputWithTooltip>
-
- <InputWithTooltip
- label="Azure AD Token"
- tooltip="Optional: Azure Active Directory token for authentication"
- >
- <Input.Password
- value={component.config.azure_ad_token}
- onChange={(e) =>
- handleConfigUpdate("azure_ad_token", e.target.value)
- }
- />
- </InputWithTooltip>
- </div>
- </DetailGroup>
-
- <DetailGroup title="Model Parameters">
- <ArgumentsFields />
- </DetailGroup>
- </div>
- );
- }
-
- return null;
-};
-
-export default React.memo(ModelFields);
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/api.ts b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/api.ts
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/api.ts
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/api.ts
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/builder.css b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/builder.css
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/builder.css
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/builder.css
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/builder.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/builder.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/builder.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/builder.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/component-editor.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/component-editor.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/component-editor.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/component-editor.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/detailgroup.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/detailgroup.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/detailgroup.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/detailgroup.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/fields/agent-fields.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/agent-fields.tsx
similarity index 91%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/fields/agent-fields.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/agent-fields.tsx
index 8be2942c2..429b60aa4 100644
--- a/python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/fields/agent-fields.tsx
+++ b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/agent-fields.tsx
@@ -357,7 +357,6 @@ export const AgentFields: React.FC<AgentFieldsProps> = ({
)}
{isWebSurferAgent(component) && (
- // Web surfer specific configuration fields...
<>
<InputWithTooltip
label="Name"
@@ -402,6 +401,44 @@ export const AgentFields: React.FC<AgentFieldsProps> = ({
}
/>
</InputWithTooltip>
+
+ {/* Added Model Client Section for WebSurferAgent */}
+ <div className="space-y-2">
+ <span className="text-sm font-medium text-primary">
+ Model Client
+ </span>
+ {component.config.model_client ? (
+ <div className="bg-secondary p-1 px-2 rounded-md">
+ <div className="flex items-center justify-between">
+ <span className="text-sm">
+ {component.config.model_client.config.model}
+ </span>
+ <div className="flex items-center justify-between">
+ {onNavigate && (
+ <Button
+ type="text"
+ icon={<Edit className="w-4 h-4" />}
+ onClick={() =>
+ onNavigate(
+ "model",
+ component.config.model_client?.label || "",
+ "model_client"
+ )
+ }
+ >
+ Configure Model
+ </Button>
+ )}
+ </div>
+ </div>
+ </div>
+ ) : (
+ <div className="text-sm text-secondary text-center bg-secondary/50 p-4 rounded-md">
+ No model configured
+ </div>
+ )}
+ </div>
+
<div className="flex items-center justify-between">
<span className="text-sm font-medium text-primary">
Headless
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/fields/fields.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/fields.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/fields/fields.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/fields.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/model-fields.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/model-fields.tsx
new file mode 100644
index 000000000..21e2bf443
--- /dev/null
+++ b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/model-fields.tsx
@@ -0,0 +1,489 @@
+import React, { useCallback } from "react";
+import { Input, InputNumber, Select, Tooltip } from "antd";
+import { HelpCircle } from "lucide-react";
+import {
+ Component,
+ ComponentConfig,
+ ModelConfig,
+} from "../../../../../types/datamodel";
+import {
+ isOpenAIModel,
+ isAzureOpenAIModel,
+ isAnthropicModel,
+} from "../../../../../types/guards";
+import DetailGroup from "../detailgroup";
+import TextArea from "antd/es/input/TextArea";
+
+interface ModelFieldsProps {
+ component: Component<ModelConfig>;
+ onChange: (updates: Partial<Component<ComponentConfig>>) => void;
+}
+
+const InputWithTooltip: React.FC<{
+ label: string;
+ tooltip: string;
+ children: React.ReactNode;
+}> = ({ label, tooltip, children }) => (
+ <label className="block">
+ <div className="flex items-center gap-2 mb-1">
+ <span className="text-sm font-medium text-primary">{label}</span>
+ <Tooltip title={tooltip}>
+ <HelpCircle className="w-4 h-4 text-secondary" />
+ </Tooltip>
+ </div>
+ {children}
+ </label>
+);
+
+// Define possible field names to ensure type safety
+type FieldName =
+ | "temperature"
+ | "max_tokens"
+ | "top_p"
+ | "top_k"
+ | "frequency_penalty"
+ | "presence_penalty"
+ | "stop"
+ | "stop_sequences"
+ | "model"
+ | "api_key"
+ | "organization"
+ | "base_url"
+ | "timeout"
+ | "max_retries"
+ | "azure_endpoint"
+ | "azure_deployment"
+ | "api_version"
+ | "azure_ad_token"
+ | "tools"
+ | "tool_choice"
+ | "metadata";
+
+// Define the field specification type
+interface FieldSpec {
+ label: string;
+ tooltip: string;
+ component: React.ComponentType<any>;
+ props: Record<string, any>;
+ transform?: {
+ fromConfig: (value: any) => any;
+ toConfig: (value: any, origValue?: any) => any;
+ };
+}
+
+// Field specifications for all possible model parameters
+const fieldSpecs: Record<FieldName, FieldSpec> = {
+ // Common fields
+ temperature: {
+ label: "Temperature",
+ tooltip:
+ "Controls randomness in the model's output. Higher values make output more random, lower values make it more focused.",
+ component: InputNumber,
+ props: { min: 0, max: 2, step: 0.1, className: "w-full" },
+ },
+ max_tokens: {
+ label: "Max Tokens",
+ tooltip: "Maximum length of the model's output in tokens",
+ component: InputNumber,
+ props: { min: 1, className: "w-full" },
+ },
+ top_p: {
+ label: "Top P",
+ tooltip:
+ "Controls diversity via nucleus sampling. Lower values make output more focused, higher values make it more diverse.",
+ component: InputNumber,
+ props: { min: 0, max: 1, step: 0.1, className: "w-full" },
+ },
+ top_k: {
+ label: "Top K",
+ tooltip:
+ "Limits the next token selection to the K most likely tokens. Only used by some models.",
+ component: InputNumber,
+ props: { min: 0, className: "w-full" },
+ },
+ frequency_penalty: {
+ label: "Frequency Penalty",
+ tooltip:
+ "Decreases the model's likelihood to repeat the same information. Values range from -2.0 to 2.0.",
+ component: InputNumber,
+ props: { min: -2, max: 2, step: 0.1, className: "w-full" },
+ },
+ presence_penalty: {
+ label: "Presence Penalty",
+ tooltip:
+ "Increases the model's likelihood to talk about new topics. Values range from -2.0 to 2.0.",
+ component: InputNumber,
+ props: { min: -2, max: 2, step: 0.1, className: "w-full" },
+ },
+ stop: {
+ label: "Stop Sequences",
+ tooltip: "Sequences where the model will stop generating further tokens",
+ component: Select,
+ props: {
+ mode: "tags",
+ placeholder: "Enter stop sequences",
+ className: "w-full",
+ },
+ },
+ stop_sequences: {
+ label: "Stop Sequences",
+ tooltip: "Sequences where the model will stop generating further tokens",
+ component: Select,
+ props: {
+ mode: "tags",
+ placeholder: "Enter stop sequences",
+ className: "w-full",
+ },
+ },
+ model: {
+ label: "Model",
+ tooltip: "The name of the model to use",
+ component: Input,
+ props: { required: true },
+ },
+
+ // OpenAI specific
+ api_key: {
+ label: "API Key",
+ tooltip: "Your API key",
+ component: Input.Password,
+ props: {},
+ },
+ organization: {
+ label: "Organization",
+ tooltip: "Optional: Your OpenAI organization ID",
+ component: Input,
+ props: {},
+ },
+ base_url: {
+ label: "Base URL",
+ tooltip: "Optional: Custom base URL for API requests",
+ component: Input,
+ props: {},
+ },
+ timeout: {
+ label: "Timeout",
+ tooltip: "Request timeout in seconds",
+ component: InputNumber,
+ props: { min: 1, className: "w-full" },
+ },
+ max_retries: {
+ label: "Max Retries",
+ tooltip: "Maximum number of retry attempts for failed requests",
+ component: InputNumber,
+ props: { min: 0, className: "w-full" },
+ },
+
+ // Azure OpenAI specific
+ azure_endpoint: {
+ label: "Azure Endpoint",
+ tooltip: "Your Azure OpenAI service endpoint URL",
+ component: Input,
+ props: { required: true },
+ },
+ azure_deployment: {
+ label: "Azure Deployment",
+ tooltip: "The name of your Azure OpenAI model deployment",
+ component: Input,
+ props: {},
+ },
+ api_version: {
+ label: "API Version",
+ tooltip: "Azure OpenAI API version (e.g., 2023-05-15)",
+ component: Input,
+ props: { required: true },
+ },
+ azure_ad_token: {
+ label: "Azure AD Token",
+ tooltip: "Optional: Azure Active Directory token for authentication",
+ component: Input.Password,
+ props: {},
+ },
+
+ // Anthropic specific
+ tools: {
+ label: "Tools",
+ tooltip: "JSON definition of tools the model can use",
+ component: TextArea,
+ props: { rows: 4, placeholder: "Enter tools JSON definition" },
+ transform: {
+ fromConfig: (value: any) => (value ? JSON.stringify(value, null, 2) : ""),
+ toConfig: (value: string) => {
+ try {
+ return value ? JSON.parse(value) : null;
+ } catch (e) {
+ return value; // Keep as string if invalid JSON
+ }
+ },
+ },
+ },
+ tool_choice: {
+ label: "Tool Choice",
+ tooltip:
+ "Controls whether the model uses tools ('auto', 'any', 'none', or JSON object)",
+ component: Select,
+ props: {
+ options: [
+ { label: "Auto", value: "auto" },
+ { label: "Any", value: "any" },
+ { label: "None", value: "none" },
+ { label: "Custom", value: "custom" },
+ ],
+ className: "w-full",
+ },
+ transform: {
+ fromConfig: (value: any) => {
+ if (typeof value === "object") return "custom";
+ return value || "auto";
+ },
+ toConfig: (value: string, origValue: any) => {
+ if (value !== "custom") return value;
+ // If it was custom before, keep the original object
+ return typeof origValue === "object" ? origValue : { type: "function" };
+ },
+ },
+ },
+ metadata: {
+ label: "Metadata",
+ tooltip: "Optional: Custom metadata to include with the request",
+ component: TextArea,
+ props: { rows: 2, placeholder: "Enter metadata as JSON" },
+ transform: {
+ fromConfig: (value: any) => (value ? JSON.stringify(value, null, 2) : ""),
+ toConfig: (value: string) => {
+ try {
+ return value ? JSON.parse(value) : null;
+ } catch (e) {
+ return value; // Keep as string if invalid JSON
+ }
+ },
+ },
+ },
+};
+
+// Define provider field mapping type
+type ProviderType = "openai" | "azure" | "anthropic";
+
+interface ProviderFields {
+ modelConfig: FieldName[];
+ modelParams: FieldName[];
+}
+
+// Define which fields each provider uses
+const providerFields: Record<ProviderType, ProviderFields> = {
+ openai: {
+ modelConfig: [
+ "model",
+ "api_key",
+ "organization",
+ "base_url",
+ "timeout",
+ "max_retries",
+ ],
+ modelParams: [
+ "temperature",
+ "max_tokens",
+ "top_p",
+ "frequency_penalty",
+ "presence_penalty",
+ "stop",
+ ],
+ },
+ azure: {
+ modelConfig: [
+ "model",
+ "api_key",
+ "azure_endpoint",
+ "azure_deployment",
+ "api_version",
+ "azure_ad_token",
+ "timeout",
+ "max_retries",
+ ],
+ modelParams: [
+ "temperature",
+ "max_tokens",
+ "top_p",
+ "frequency_penalty",
+ "presence_penalty",
+ "stop",
+ ],
+ },
+ anthropic: {
+ modelConfig: ["model", "api_key", "base_url", "timeout", "max_retries"],
+ modelParams: [
+ "temperature",
+ "max_tokens",
+ "top_p",
+ "top_k",
+ "stop_sequences",
+ "tools",
+ "tool_choice",
+ "metadata",
+ ],
+ },
+};
+
+export const ModelFields: React.FC<ModelFieldsProps> = ({
+ component,
+ onChange,
+}) => {
+ // Determine which provider we're dealing with
+ let providerType: ProviderType | null = null;
+ if (isOpenAIModel(component)) {
+ providerType = "openai";
+ } else if (isAzureOpenAIModel(component)) {
+ providerType = "azure";
+ } else if (isAnthropicModel(component)) {
+ providerType = "anthropic";
+ }
+
+ // Return null if we don't recognize the provider
+ if (!providerType) return null;
+
+ const handleComponentUpdate = useCallback(
+ (updates: Partial<Component<ComponentConfig>>) => {
+ onChange({
+ ...component,
+ ...updates,
+ config: {
+ ...component.config,
+ ...(updates.config || {}),
+ },
+ });
+ },
+ [component, onChange]
+ );
+
+ const handleConfigUpdate = useCallback(
+ (field: FieldName, value: unknown) => {
+ // Check if this field has a transform function
+ const spec = fieldSpecs[field];
+ const transformedValue = spec.transform?.toConfig
+ ? spec.transform.toConfig(value, (component.config as any)[field])
+ : value;
+
+ handleComponentUpdate({
+ config: {
+ ...component.config,
+ [field]: transformedValue,
+ },
+ });
+ },
+ [component, handleComponentUpdate]
+ );
+
+ // Function to render a single field
+ const renderField = (fieldName: FieldName) => {
+ const spec = fieldSpecs[fieldName];
+ if (!spec) return null;
+
+ // Get the current value, applying any transformation
+ const value = spec.transform?.fromConfig
+ ? spec.transform.fromConfig((component.config as any)[fieldName])
+ : (component.config as any)[fieldName];
+
+ return (
+ <InputWithTooltip
+ key={fieldName}
+ label={spec.label}
+ tooltip={spec.tooltip}
+ >
+ <spec.component
+ {...spec.props}
+ value={value}
+ onChange={(val: any) => {
+ // For some components like Input, the value is in e.target.value
+ const newValue = val && val.target ? val.target.value : val;
+ handleConfigUpdate(fieldName, newValue);
+ }}
+ />
+ </InputWithTooltip>
+ );
+ };
+
+ // Function to render a group of fields
+ const renderFieldGroup = (fields: FieldName[]) => {
+ return (
+ <div className="space-y-4">
+ {fields.map((field) => renderField(field))}
+ </div>
+ );
+ };
+
+ return (
+ <div className="space-y-6">
+ <DetailGroup title="Component Details">
+ <div className="space-y-4">
+ <label className="block">
+ <span className="text-sm font-medium text-primary">Name</span>
+ <Input
+ value={component.label || ""}
+ onChange={(e) => handleComponentUpdate({ label: e.target.value })}
+ placeholder="Model name"
+ className="mt-1"
+ />
+ </label>
+
+ <label className="block">
+ <span className="text-sm font-medium text-primary">
+ Description
+ </span>
+ <TextArea
+ value={component.description || ""}
+ onChange={(e) =>
+ handleComponentUpdate({ description: e.target.value })
+ }
+ placeholder="Model description"
+ rows={4}
+ className="mt-1"
+ />
+ </label>
+ </div>
+ </DetailGroup>
+
+ <DetailGroup
+ title={
+ providerType === "azure"
+ ? "Azure Configuration"
+ : "Model Configuration"
+ }
+ >
+ {renderFieldGroup(providerFields[providerType].modelConfig)}
+ </DetailGroup>
+
+ <DetailGroup title="Model Parameters">
+ {renderFieldGroup(providerFields[providerType].modelParams)}
+ </DetailGroup>
+
+ {/* Only render tool configuration if it's an Anthropic model and has tools */}
+ {providerType === "anthropic" &&
+ (component.config as any).tool_choice === "custom" && (
+ <DetailGroup title="Custom Tool Choice">
+ <div className="space-y-4">
+ <TextArea
+ value={JSON.stringify(
+ (component.config as any).tool_choice,
+ null,
+ 2
+ )}
+ onChange={(e) => {
+ try {
+ const value = JSON.parse(e.target.value);
+ handleConfigUpdate("tool_choice" as FieldName, value);
+ } catch (err) {
+ // Handle invalid JSON
+ console.error("Invalid JSON for tool_choice");
+ }
+ }}
+ placeholder="Enter tool choice configuration as JSON"
+ rows={4}
+ />
+ </div>
+ </DetailGroup>
+ )}
+ </div>
+ );
+};
+
+export default React.memo(ModelFields);
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/fields/team-fields.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/team-fields.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/fields/team-fields.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/team-fields.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/fields/termination-fields.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/termination-fields.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/fields/termination-fields.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/termination-fields.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/fields/tool-fields.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/tool-fields.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/component-editor/fields/tool-fields.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/component-editor/fields/tool-fields.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/library.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/library.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/library.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/library.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/node-editor/fields/agent-fields.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/node-editor/fields/agent-fields.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/node-editor/fields/agent-fields.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/node-editor/fields/agent-fields.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/node-editor/fields/fields.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/node-editor/fields/fields.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/node-editor/fields/fields.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/node-editor/fields/fields.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/node-editor/fields/model-fields.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/node-editor/fields/model-fields.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/node-editor/fields/model-fields.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/node-editor/fields/model-fields.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/node-editor/fields/team-fields.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/node-editor/fields/team-fields.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/node-editor/fields/team-fields.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/node-editor/fields/team-fields.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/node-editor/fields/termination-fields.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/node-editor/fields/termination-fields.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/node-editor/fields/termination-fields.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/node-editor/fields/termination-fields.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/node-editor/fields/tool-fields.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/node-editor/fields/tool-fields.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/node-editor/fields/tool-fields.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/node-editor/fields/tool-fields.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/nodes.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/nodes.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/nodes.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/nodes.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/store.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/store.tsx
similarity index 99%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/store.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/store.tsx
index dc6101ed3..4b88b5f9d 100644
--- a/python/packages/autogen-studio/frontend/src/components/views/team/builder/store.tsx
+++ b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/store.tsx
@@ -28,6 +28,7 @@ import {
isModelComponent,
isSelectorTeam,
isAssistantAgent,
+ isWebSurferAgent,
} from "../../../types/guards";
const MAX_HISTORY = 50;
@@ -137,7 +138,8 @@ export const useTeamBuilderStore = create<TeamBuilderState>((set, get) => ({
};
} else if (
isAgentComponent(targetNode.data.component) &&
- isAssistantAgent(targetNode.data.component)
+ (isAssistantAgent(targetNode.data.component) ||
+ isWebSurferAgent(targetNode.data.component))
) {
targetNode.data.component.config.model_client = clonedComponent;
return {
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/testdrawer.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/testdrawer.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/testdrawer.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/testdrawer.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/toolbar.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/toolbar.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/toolbar.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/toolbar.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/types.ts b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/types.ts
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/types.ts
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/types.ts
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/utils.ts b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/utils.ts
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/utils.ts
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/utils.ts
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/builder/validationerrors.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/validationerrors.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/builder/validationerrors.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/builder/validationerrors.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/hooks.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/hooks.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/hooks.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/hooks.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/manager.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/manager.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/manager.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/manager.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/sidebar.tsx b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/sidebar.tsx
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/sidebar.tsx
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/sidebar.tsx
diff --git a/python/packages/autogen-studio/frontend/src/components/views/team/types.ts b/python/packages/autogen-studio/frontend/src/components/views/teambuilder/types.ts
similarity index 100%
rename from python/packages/autogen-studio/frontend/src/components/views/team/types.ts
rename to python/packages/autogen-studio/frontend/src/components/views/teambuilder/types.ts
diff --git a/python/packages/autogen-studio/frontend/src/pages/build.tsx b/python/packages/autogen-studio/frontend/src/pages/build.tsx
index e70a65463..0336a157d 100644
--- a/python/packages/autogen-studio/frontend/src/pages/build.tsx
+++ b/python/packages/autogen-studio/frontend/src/pages/build.tsx
@@ -1,7 +1,7 @@
import * as React from "react";
import Layout from "../components/layout";
import { graphql } from "gatsby";
-import TeamManager from "../components/views/team/manager";
+import TeamManager from "../components/views/teambuilder/manager";
// markup
const IndexPage = ({ data }: any) => {