Skip to content

Commit e50737f

Browse files
authored
style: apply ruff format to Python codebase (CopilotKit#4813)
## Summary One-time `ruff format .` across the Python codebase — 320 files, 7759+/4678-. This aligns the existing Python code with the ruff format check added in CopilotKit#4812. Without this, the push-to-main format job fails on every merge that touches the `static / quality` workflow. ## Why a separate PR Pure formatting, no behavioral changes. Keeping it isolated makes git blame clean — one commit to skip, not interleaved with logic changes. ## Test plan - [ ] CI format job passes (the whole point) - [ ] Python unit tests unaffected (formatting only)
2 parents 4066aaa + 2482317 commit e50737f

320 files changed

Lines changed: 7759 additions & 4678 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

examples/canvas/gemini/agent/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
from dotenv import load_dotenv
77

8-
load_dotenv()
8+
load_dotenv()
99

1010
from fastapi import FastAPI
1111
import uvicorn

examples/canvas/gemini/agent/posts_generator_agent.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55
from langchain_google_genai import ChatGoogleGenerativeAI
66
from prompts import system_prompt, system_prompt_3, system_prompt_4
7+
78
load_dotenv()
89
from typing import Dict, List, Any
910
from langchain_core.runnables import RunnableConfig
@@ -16,6 +17,7 @@
1617
import uuid
1718
import asyncio
1819

20+
1921
# Define the agent's runtime state schema for CopilotKit/LangGraph
2022
class AgentState(CopilotKitState):
2123
tool_logs: List[Dict[str, Any]]
@@ -43,9 +45,9 @@ async def chat_node(state: AgentState, config: RunnableConfig):
4345
google_api_key=os.getenv("GOOGLE_API_KEY"),
4446
)
4547
messages = [*state["messages"]]
46-
messages[-1].content = (
47-
"The posts had been generated successfully. Just generate a summary of the posts."
48-
)
48+
messages[
49+
-1
50+
].content = "The posts had been generated successfully. Just generate a summary of the posts."
4951
resp = await client.ainvoke(
5052
[*state["messages"]],
5153
config,
@@ -62,19 +64,17 @@ async def chat_node(state: AgentState, config: RunnableConfig):
6264
if config is None:
6365
config = RunnableConfig(recursion_limit=25)
6466
else:
65-
config = copilotkit_customize_config(config, emit_messages=True, emit_tool_calls=True)
67+
config = copilotkit_customize_config(
68+
config, emit_messages=True, emit_tool_calls=True
69+
)
6670
# 4. Generating the response using the model. This returns the response along with the web search queries.
6771
response = await model.aio.models.generate_content(
6872
model="gemini-2.5-pro",
6973
contents=[
7074
types.Content(role="user", parts=[types.Part(text=system_prompt)]),
7175
types.Content(
7276
role="model",
73-
parts=[
74-
types.Part(
75-
text= system_prompt_4
76-
)
77-
],
77+
parts=[types.Part(text=system_prompt_4)],
7878
),
7979
types.Content(
8080
role="user", parts=[types.Part(text=state["messages"][-1].content)]
@@ -86,11 +86,17 @@ async def chat_node(state: AgentState, config: RunnableConfig):
8686
state["tool_logs"][-1]["status"] = "completed"
8787
await copilotkit_emit_state(config, state)
8888
state["response"] = response.text
89-
89+
9090
# 6. Orchestrating the web search queries and updating the tool logs
91-
grounding = getattr(response.candidates[0], "grounding_metadata", None) if response.candidates else None
92-
search_queries = getattr(grounding, "web_search_queries", None) if grounding else None
93-
for query in (search_queries or []):
91+
grounding = (
92+
getattr(response.candidates[0], "grounding_metadata", None)
93+
if response.candidates
94+
else None
95+
)
96+
search_queries = (
97+
getattr(grounding, "web_search_queries", None) if grounding else None
98+
)
99+
for query in search_queries or []:
94100
state["tool_logs"].append(
95101
{
96102
"id": str(uuid.uuid4()),
@@ -108,7 +114,7 @@ async def chat_node(state: AgentState, config: RunnableConfig):
108114
async def fe_actions_node(state: AgentState, config: RunnableConfig):
109115
if len(state["messages"]) >= 2 and state["messages"][-2].type == "tool":
110116
return Command(goto="end_node", update=state)
111-
117+
112118
state["tool_logs"].append(
113119
{
114120
"id": str(uuid.uuid4()),

examples/canvas/gemini/agent/prompts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@
4848
"""
4949

5050
system_prompt_4 = """I understand. I will use the google_search tool when needed to provide current and accurate information.
51-
"""
51+
"""

examples/canvas/gemini/agent/stack_agent.py

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ class StackAgentState(CopilotKitState):
3131
tool_logs: List[Dict[str, Any]]
3232
analysis: Dict[str, Any]
3333
show_cards: bool
34-
context : Dict[str, Any]
35-
last_user_content : str
34+
context: Dict[str, Any]
35+
last_user_content: str
3636

3737

3838
# -------------------- Structured Output Schema --------------------
@@ -95,7 +95,6 @@ class StructuredStackAnalysis(BaseModel):
9595
risks_notes: List[RiskNoteSpec] = Field(default_factory=list)
9696

9797

98-
9998
# Expose a tool to return the structured stack analysis to the caller
10099
@tool("return_stack_analysis", args_schema=StructuredStackAnalysis)
101100
def return_stack_analysis_tool(**kwargs) -> Dict[str, Any]:
@@ -282,19 +281,18 @@ async def gather_context_node(state: StackAgentState, config: RunnableConfig):
282281
# Parse the last user message for a GitHub URL; fall back when absent
283282
last_user_content = state["messages"][-1].content if state["messages"] else ""
284283
parsed = _parse_github_url(last_user_content)
285-
284+
286285
if not parsed:
287286
return Command(
288-
goto= "analyze",
289-
update = {
287+
goto="analyze",
288+
update={
290289
"analysis": state["analysis"],
291290
"context": {},
292291
"tool_logs": state["tool_logs"],
293292
"show_cards": False,
294-
"last_user_content": last_user_content
295-
}
296-
)
297-
293+
"last_user_content": last_user_content,
294+
},
295+
)
298296

299297
# 2. Create a log entry for URL extraction
300298
state["tool_logs"] = state.get("tool_logs", [])
@@ -307,7 +305,6 @@ async def gather_context_node(state: StackAgentState, config: RunnableConfig):
307305
)
308306
await copilotkit_emit_state(config, state)
309307

310-
311308
owner, repo = parsed
312309
state["tool_logs"][-1]["status"] = "completed"
313310
await copilotkit_emit_state(config, state)
@@ -345,30 +342,30 @@ async def gather_context_node(state: StackAgentState, config: RunnableConfig):
345342
await copilotkit_emit_state(config, state)
346343

347344
return Command(
348-
goto= "analyze",
349-
update = {
345+
goto="analyze",
346+
update={
350347
"analysis": state["analysis"],
351348
"context": context,
352349
"tool_logs": state["tool_logs"],
353350
"show_cards": False,
354-
"last_user_content": last_user_content
355-
}
351+
"last_user_content": last_user_content,
352+
},
356353
)
357354

358355

359356
async def analyze_with_gemini_node(state: StackAgentState, config: RunnableConfig):
360357
# 6. Short-circuit when no context exists and request a valid URL
361-
358+
362359
context = state.get("context", {})
363360
if not context:
364-
state["messages"].append(AIMessage(content= "Please provide a valid GitHub URL"))
361+
state["messages"].append(AIMessage(content="Please provide a valid GitHub URL"))
365362
return Command(
366-
goto= "end",
367-
update = {
363+
goto="end",
364+
update={
368365
"messages": state["messages"],
369366
"show_cards": state["show_cards"],
370-
"analysis": state["analysis"]
371-
}
367+
"analysis": state["analysis"],
368+
},
372369
)
373370

374371
# 7. Begin analysis and emit progress
@@ -413,8 +410,8 @@ async def analyze_with_gemini_node(state: StackAgentState, config: RunnableConfi
413410
for call in tool_calls:
414411
if call.get("name") == "return_stack_analysis":
415412
args = call.get("args", {}) or {}
416-
state['analysis'] = json.dumps(args)
417-
state['show_cards'] = True
413+
state["analysis"] = json.dumps(args)
414+
state["show_cards"] = True
418415
await copilotkit_emit_state(config, state)
419416
try:
420417
structured_payload = StructuredStackAnalysis(
@@ -448,31 +445,47 @@ async def analyze_with_gemini_node(state: StackAgentState, config: RunnableConfi
448445
await copilotkit_emit_state(config, state)
449446
messages[-1].content = state["last_user_content"]
450447
if tool_calls and tool_msg:
451-
messages.append(AIMessage(tool_calls=tool_calls, id=tool_msg.id, type="ai", content=''))
452-
messages.append(ToolMessage(content="The GitHub Repository has been analyzed", tool_call_id=tool_calls[0]["id"], type="tool"))
453-
messages[0].content = "Generate a summary of the GitHub Repository. It should be in a concise and strictly textual"
454-
448+
messages.append(
449+
AIMessage(tool_calls=tool_calls, id=tool_msg.id, type="ai", content="")
450+
)
451+
messages.append(
452+
ToolMessage(
453+
content="The GitHub Repository has been analyzed",
454+
tool_call_id=tool_calls[0]["id"],
455+
type="tool",
456+
)
457+
)
458+
messages[
459+
0
460+
].content = "Generate a summary of the GitHub Repository. It should be in a concise and strictly textual"
461+
455462
# 13. Generate a user-facing summary referencing the tool call outcome
456463
client = ChatGoogleGenerativeAI(
457464
model="gemini-2.5-pro",
458465
temperature=0.4,
459466
max_retries=2,
460467
google_api_key=os.getenv("GOOGLE_API_KEY"),
461468
)
462-
state["tool_logs"].append({"id": str(uuid.uuid4()), "message": "Generating Summary", "status": "processing"})
469+
state["tool_logs"].append(
470+
{
471+
"id": str(uuid.uuid4()),
472+
"message": "Generating Summary",
473+
"status": "processing",
474+
}
475+
)
463476
await copilotkit_emit_state(config, state)
464477
model_response = await client.ainvoke(messages, config)
465478
state["tool_logs"][-1]["status"] = "completed"
466479
await copilotkit_emit_state(config, state)
467480
state["messages"].append(AIMessage(content=model_response.content))
468481
# 14. Return a message containing the analysis
469482
return Command(
470-
goto= "end",
471-
update = {
483+
goto="end",
484+
update={
472485
"messages": state["messages"],
473486
"show_cards": True,
474-
"analysis": state["analysis"]
475-
}
487+
"analysis": state["analysis"],
488+
},
476489
)
477490

478491

@@ -482,12 +495,12 @@ async def end_node(state: StackAgentState, config: RunnableConfig):
482495
state["tool_logs"] = []
483496
await copilotkit_emit_state(config or RunnableConfig(recursion_limit=25), state)
484497
return Command(
485-
goto= END,
486-
update = {
498+
goto=END,
499+
update={
487500
"messages": state["messages"],
488501
"show_cards": state["show_cards"],
489-
"analysis": state["analysis"]
490-
}
502+
"analysis": state["analysis"],
503+
},
491504
)
492505

493506

0 commit comments

Comments
 (0)