Skip to content

Commit b1e0ad6

Browse files
authored
Merge branch 'main' into grok-4-usecase-Image-inputs
2 parents 9708afc + 00aa376 commit b1e0ad6

File tree

19 files changed

+170
-68
lines changed

19 files changed

+170
-68
lines changed

.github/workflows/claude-code-review.yml

Lines changed: 68 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,6 @@ on:
77
- opened
88
- synchronize
99
- ready_for_review
10-
# Optional: Only run on specific file changes
11-
# paths:
12-
# - "src/**/*.ts"
13-
# - "src/**/*.tsx"
14-
# - "src/**/*.js"
15-
# - "src/**/*.jsx"
1610
# For PRs from forked repositories (secure path with secrets)
1711
pull_request_target:
1812
types:
@@ -21,14 +15,12 @@ on:
2115
- ready_for_review
2216

2317
jobs:
24-
claude-review:
25-
# Skip draft PRs and prevent duplicate runs
18+
# Job for same-repo PRs (can use OIDC if needed)
19+
claude-review-same-repo:
2620
if: |
27-
github.event.pull_request.draft == false &&
28-
(
29-
(github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository) ||
30-
(github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository)
31-
)
21+
github.event_name == 'pull_request' &&
22+
github.event.pull_request.head.repo.full_name == github.repository &&
23+
github.event.pull_request.draft == false
3224
3325
runs-on: ubuntu-latest
3426
permissions:
@@ -47,12 +39,65 @@ jobs:
4739
env:
4840
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4941
run: |
50-
if [ "${{ github.event_name }}" = "pull_request_target" ]; then
51-
echo "⚠️ Forked PR detected - running in secure mode"
52-
echo "PR from: ${{ github.event.pull_request.head.repo.full_name }}"
53-
echo "Base repo: ${{ github.repository }}"
54-
fi
42+
echo "Checking out PR #${{ github.event.pull_request.number }}"
43+
gh pr checkout ${{ github.event.pull_request.number }}
44+
echo "✅ PR branch checked out successfully"
45+
46+
- name: Run Claude Code Review
47+
id: claude-review
48+
uses: anthropics/claude-code-action@v1
49+
with:
50+
github_token: ${{ secrets.GITHUB_TOKEN }}
51+
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
52+
prompt: |
53+
REPO: ${{ github.repository }}
54+
PR NUMBER: ${{ github.event.pull_request.number }}
55+
56+
Please review this pull request and provide feedback on:
57+
- Code quality and best practices
58+
- Potential bugs or issues
59+
- Performance considerations
60+
- Security concerns
61+
- Test coverage
62+
63+
# Steps to run a Review:
64+
1) Check if previous review is already done by Claude. If so, perform a re-reivew with the latest changes referring previous review.
65+
2) If no previous review is found, perform a new review with the latest changes.
66+
67+
Use the repository's CLAUDE.md for guidance on style and conventions. Be constructive and helpful in your feedback.
68+
69+
Use `gh pr comment` with your Bash tool to leave your review as a comment on the PR.
5570
71+
claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)"'
72+
73+
# Job for forked PRs (no OIDC, token-based only)
74+
claude-review-forked:
75+
if: |
76+
github.event_name == 'pull_request_target' &&
77+
github.event.pull_request.head.repo.full_name != github.repository &&
78+
github.event.pull_request.draft == false
79+
80+
runs-on: ubuntu-latest
81+
permissions:
82+
contents: read
83+
pull-requests: write
84+
issues: read
85+
# Explicitly disable id-token to avoid OIDC flow
86+
87+
steps:
88+
- name: Checkout repository (no credentials persisted)
89+
uses: actions/checkout@v4
90+
with:
91+
fetch-depth: 1
92+
persist-credentials: false
93+
94+
- name: Checkout PR branch (forked PR)
95+
env:
96+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
97+
run: |
98+
echo "⚠️ Forked PR detected - running in secure mode"
99+
echo "PR from: ${{ github.event.pull_request.head.repo.full_name }}"
100+
echo "Base repo: ${{ github.repository }}"
56101
echo "Checking out PR #${{ github.event.pull_request.number }}"
57102
gh pr checkout ${{ github.event.pull_request.number }}
58103
echo "✅ PR branch checked out successfully"
@@ -61,6 +106,7 @@ jobs:
61106
id: claude-review
62107
uses: anthropics/claude-code-action@v1
63108
with:
109+
github_token: ${{ secrets.GITHUB_TOKEN }}
64110
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
65111
prompt: |
66112
REPO: ${{ github.repository }}
@@ -73,10 +119,12 @@ jobs:
73119
- Security concerns
74120
- Test coverage
75121
122+
# Steps to run a Review:
123+
1) Check if previous review is already done by Claude. If so, perform a re-reivew with the latest changes referring previous review.
124+
2) If no previous review is found, perform a new review with the latest changes.
125+
76126
Use the repository's CLAUDE.md for guidance on style and conventions. Be constructive and helpful in your feedback.
77127
78128
Use `gh pr comment` with your Bash tool to leave your review as a comment on the PR.
79129
80-
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
81-
# or https://docs.claude.com/en/docs/claude-code/cli-reference for available options
82130
claude_args: '--allowed-tools "Bash(gh issue view:*),Bash(gh search:*),Bash(gh issue list:*),Bash(gh pr comment:*),Bash(gh pr diff:*),Bash(gh pr view:*),Bash(gh pr list:*)"'

autogen/agentchat/group/safeguards/events.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,34 @@
55
from __future__ import annotations
66

77
from collections.abc import Callable
8-
from typing import Any
8+
from typing import Any, Literal
99
from uuid import UUID
1010

1111
from termcolor import colored
1212

1313
from ....events.base_event import BaseEvent, wrap_event
1414

15+
# Type for termcolor colors
16+
TermColor = Literal[
17+
"black",
18+
"grey",
19+
"red",
20+
"green",
21+
"yellow",
22+
"blue",
23+
"magenta",
24+
"cyan",
25+
"light_grey",
26+
"dark_grey",
27+
"light_red",
28+
"light_green",
29+
"light_yellow",
30+
"light_blue",
31+
"light_magenta",
32+
"light_cyan",
33+
"white",
34+
]
35+
1536

1637
@wrap_event
1738
class SafeguardEvent(BaseEvent):
@@ -52,7 +73,7 @@ def print(self, f: Callable[..., Any] | None = None) -> None:
5273
f = f or print
5374

5475
# Choose color based on event type
55-
color = "green"
76+
color: TermColor = "green"
5677
if self.event_type == "load":
5778
color = "green"
5879
elif self.event_type == "check":

autogen/interop/pydantic_ai/pydantic_ai.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def inject_params(
6363

6464
@wraps(f)
6565
def wrapper(*args: Any, **kwargs: Any) -> Any:
66-
current_retry = 0 if ctx_typed is None else ctx_typed.retries.get(tool_typed.name, 0)
66+
current_retry = 0 if ctx_typed is None else ctx_typed.retries.get(tool_typed.name, 0) # type: ignore[attr-defined]
6767

6868
if current_retry >= max_retries:
6969
raise ValueError(f"{tool_typed.name} failed after {max_retries} retries")
@@ -73,12 +73,12 @@ def wrapper(*args: Any, **kwargs: Any) -> Any:
7373
kwargs.pop("ctx", None)
7474
ctx_typed.retry = current_retry
7575
result = f(**kwargs, ctx=ctx_typed) # type: ignore[call-arg]
76-
ctx_typed.retries[tool_typed.name] = 0
76+
ctx_typed.retries[tool_typed.name] = 0 # type: ignore[attr-defined]
7777
else:
7878
result = f(**kwargs) # type: ignore[call-arg]
7979
except Exception as e:
8080
if ctx_typed is not None:
81-
ctx_typed.retries[tool_typed.name] = ctx_typed.retries.get(tool_typed.name, 0) + 1
81+
ctx_typed.retries[tool_typed.name] = ctx_typed.retries.get(tool_typed.name, 0) + 1 # type: ignore[attr-defined]
8282
raise e
8383

8484
return result
@@ -145,6 +145,10 @@ def convert_tool(cls, tool: Any, deps: Any = None, **kwargs: Any) -> Tool:
145145
else None
146146
)
147147

148+
# Initialize retries dict for tracking retry counts per tool
149+
if ctx is not None:
150+
ctx.retries = {} # type: ignore[attr-defined]
151+
148152
func = PydanticAIInteroperability.inject_params(
149153
ctx=ctx,
150154
tool=pydantic_ai_tool,
@@ -154,7 +158,7 @@ def convert_tool(cls, tool: Any, deps: Any = None, **kwargs: Any) -> Tool:
154158
name=pydantic_ai_tool.name,
155159
description=pydantic_ai_tool.description,
156160
func_or_tool=func,
157-
parameters_json_schema=pydantic_ai_tool.function_schema.json_schema,
161+
parameters_json_schema=pydantic_ai_tool.function_schema.json_schema, # type: ignore[attr-defined]
158162
)
159163

160164
@classmethod

autogen/llm_config/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class ModelClient(Protocol):
3232
class ModelClientResponseProtocol(Protocol):
3333
class Choice(Protocol):
3434
class Message(Protocol):
35-
content: str | dict[str, Any] | list[dict[str, Any]]
35+
content: str | dict[str, Any] | list[dict[str, Any]] | None
3636

3737
message: Message
3838

autogen/oai/anthropic.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ def create_client(self):
150150

151151
@require_optional_import("anthropic", "anthropic")
152152
class AnthropicClient:
153+
RESPONSE_USAGE_KEYS: list[str] = ["prompt_tokens", "completion_tokens", "total_tokens", "cost", "model"]
154+
153155
def __init__(self, **kwargs: Unpack[AnthropicEntryDict]):
154156
"""Initialize the Anthropic API client.
155157

autogen/oai/bedrock.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ def create_client(self):
9797
class BedrockClient:
9898
"""Client for Amazon's Bedrock Converse API."""
9999

100+
RESPONSE_USAGE_KEYS: list[str] = ["prompt_tokens", "completion_tokens", "total_tokens", "cost", "model"]
101+
100102
_retries = 5
101103

102104
def __init__(self, **kwargs: Unpack[BedrockEntryDict]):

autogen/oai/cerebras.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ def create_client(self):
7575
class CerebrasClient:
7676
"""Client for Cerebras's API."""
7777

78+
RESPONSE_USAGE_KEYS: list[str] = ["prompt_tokens", "completion_tokens", "total_tokens", "cost", "model"]
79+
7880
def __init__(self, api_key=None, **kwargs: Unpack[CerebrasEntryDict]):
7981
"""Requires api_key or environment variable to be set
8082

0 commit comments

Comments
 (0)