Skip to content

Commit 938cffb

Browse files
Refactors Python code for better readability
This commit refactors several Python functions to improve readability and maintainability by adjusting line breaks and spacing. Specifically, it: - Improves the formatting of conditional checks in the `_should_generate_vc` method of the `Agent` class. - Enhances the readability of function signatures in `_replace_module_reference` and `_apply_vc_metadata`. - Adjusts the formatting of `session_id` retrieval in `_execute_with_tracking`. - Corrects the formatting for checking DID execution context and attributes in `_execute_with_tracking`. Additionally, minor formatting adjustments were made in Go files related to CLI flags and response structures for consistency.
1 parent 9c84ca6 commit 938cffb

9 files changed

Lines changed: 49 additions & 42 deletions

File tree

control-plane/internal/cli/root.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ import (
1414
)
1515

1616
var (
17-
cfgFile string
18-
verbose bool
19-
openBrowserFlag bool
20-
uiDevFlag bool
21-
backendOnlyFlag bool
22-
portFlag int
23-
noVCExecution bool
24-
forceVCExecution bool
25-
storageModeFlag string
26-
postgresURLFlag string
17+
cfgFile string
18+
verbose bool
19+
openBrowserFlag bool
20+
uiDevFlag bool
21+
backendOnlyFlag bool
22+
portFlag int
23+
noVCExecution bool
24+
forceVCExecution bool
25+
storageModeFlag string
26+
postgresURLFlag string
2727
)
2828

2929
// NewRootCommand creates and returns the root Cobra command for the AgentField CLI.

control-plane/internal/handlers/workflow_dag.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ type WorkflowDAGLightweightNode struct {
7777
}
7878

7979
type WorkflowDAGLightweightResponse struct {
80-
RootWorkflowID string `json:"root_workflow_id"`
81-
WorkflowStatus string `json:"workflow_status"`
82-
WorkflowName string `json:"workflow_name"`
83-
SessionID *string `json:"session_id,omitempty"`
84-
ActorID *string `json:"actor_id,omitempty"`
85-
TotalNodes int `json:"total_nodes"`
86-
MaxDepth int `json:"max_depth"`
87-
Timeline []WorkflowDAGLightweightNode `json:"timeline"`
88-
Mode string `json:"mode"`
80+
RootWorkflowID string `json:"root_workflow_id"`
81+
WorkflowStatus string `json:"workflow_status"`
82+
WorkflowName string `json:"workflow_name"`
83+
SessionID *string `json:"session_id,omitempty"`
84+
ActorID *string `json:"actor_id,omitempty"`
85+
TotalNodes int `json:"total_nodes"`
86+
MaxDepth int `json:"max_depth"`
87+
Timeline []WorkflowDAGLightweightNode `json:"timeline"`
88+
Mode string `json:"mode"`
8989
}
9090

9191
func GetWorkflowDAGHandler(storageProvider storage.StorageProvider) gin.HandlerFunc {

sdk/go/ai/response.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ type StreamChunk struct {
4040

4141
// StreamDelta represents a delta in a streaming response.
4242
type StreamDelta struct {
43-
Index int `json:"index"`
44-
Delta MessageDelta `json:"delta"`
45-
FinishReason *string `json:"finish_reason"`
43+
Index int `json:"index"`
44+
Delta MessageDelta `json:"delta"`
45+
FinishReason *string `json:"finish_reason"`
4646
}
4747

4848
// MessageDelta represents the incremental message content.

sdk/python/agentfield/agent.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -886,8 +886,14 @@ def _effective_component_vc_setting(
886886
return overrides[component_id]
887887
return self._agent_vc_default()
888888

889-
def _should_generate_vc(self, component_id: str, overrides: Dict[str, bool]) -> bool:
890-
if not self.did_enabled or not self.vc_generator or not self.vc_generator.is_enabled():
889+
def _should_generate_vc(
890+
self, component_id: str, overrides: Dict[str, bool]
891+
) -> bool:
892+
if (
893+
not self.did_enabled
894+
or not self.vc_generator
895+
or not self.vc_generator.is_enabled()
896+
):
891897
return False
892898
return self._effective_component_vc_setting(component_id, overrides)
893899

@@ -1172,7 +1178,6 @@ async def run_reasoner() -> Any:
11721178

11731179
return await run_reasoner()
11741180

1175-
11761181
# 🔥 ENHANCED: Comprehensive function replacement for unified tracking
11771182
original_func = func
11781183

@@ -1773,7 +1778,9 @@ def include_router(
17731778
router._attach_agent(self)
17741779
normalized_prefix = prefix.rstrip("/") if prefix else ""
17751780

1776-
def _replace_module_reference(original_func: Callable, tracked_func: Callable) -> None:
1781+
def _replace_module_reference(
1782+
original_func: Callable, tracked_func: Callable
1783+
) -> None:
17771784
module_name = getattr(original_func, "__module__", None)
17781785
attr_name = getattr(original_func, "__name__", None)
17791786
if not module_name or not attr_name:

sdk/python/agentfield/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ def get_nodes(self) -> Dict[str, Any]:
326326
response.raise_for_status() # Raise an exception for bad status codes
327327
return response.json()
328328

329-
def _apply_vc_metadata(self, registration_data: Dict[str, Any], vc_metadata: Optional[Dict[str, Any]]) -> None:
329+
def _apply_vc_metadata(
330+
self, registration_data: Dict[str, Any], vc_metadata: Optional[Dict[str, Any]]
331+
) -> None:
330332
"""Attach VC metadata to the registration payload if supplied."""
331333
if not vc_metadata:
332334
return

sdk/python/agentfield/decorators.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,16 @@ async def _execute_with_tracking(func: Callable, *args, **kwargs) -> Any:
177177
)
178178
if agent_has_did:
179179
try:
180-
session_id = (
181-
execution_context.session_id or execution_context.workflow_id
182-
)
180+
session_id = execution_context.session_id or execution_context.workflow_id
183181
did_execution_context = agent_instance.did_manager.create_execution_context(
184182
execution_context.execution_id,
185183
execution_context.workflow_id,
186184
session_id,
187185
"agent",
188186
reasoner_name,
189187
)
190-
if (
191-
did_execution_context
192-
and hasattr(agent_instance, "_populate_execution_context_with_did")
188+
if did_execution_context and hasattr(
189+
agent_instance, "_populate_execution_context_with_did"
193190
):
194191
agent_instance._populate_execution_context_with_did(
195192
execution_context, did_execution_context

sdk/python/tests/test_agent_networking.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,8 @@ async def critical_reasoner(text: str) -> dict:
212212
def bulk_skill(amount: int) -> int:
213213
return amount
214214

215-
assert agent._should_generate_vc(
216-
"critical", agent._reasoner_vc_overrides
217-
) is True
218-
assert agent._should_generate_vc(
219-
"fallback", agent._reasoner_vc_overrides
220-
) is False
215+
assert agent._should_generate_vc("critical", agent._reasoner_vc_overrides) is True
216+
assert agent._should_generate_vc("fallback", agent._reasoner_vc_overrides) is False
221217
assert agent._should_generate_vc("bulk", agent._skill_vc_overrides) is True
222218

223219
metadata = agent._build_vc_metadata()

sdk/python/tests/test_async_execution.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88

99
@pytest.mark.asyncio
1010
async def test_reasoner_async_mode_sends_status(monkeypatch):
11-
agent = Agent(node_id="test-agent", agentfield_server="http://control", auto_register=False)
11+
agent = Agent(
12+
node_id="test-agent", agentfield_server="http://control", auto_register=False
13+
)
1214

1315
@agent.reasoner()
1416
async def echo(value: int) -> dict:
@@ -51,7 +53,9 @@ async def fake_request(self, method, url, **kwargs):
5153

5254
@pytest.mark.asyncio
5355
async def test_post_execution_status_retries(monkeypatch):
54-
agent = Agent(node_id="test-agent", agentfield_server="http://control", auto_register=False)
56+
agent = Agent(
57+
node_id="test-agent", agentfield_server="http://control", auto_register=False
58+
)
5559

5660
attempts = {"count": 0}
5761

sdk/python/tests/test_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,5 +366,6 @@ def on_request(method, url, **kwargs):
366366
assert posted[0][1].endswith("/nodes/register")
367367
body = posted[0][2]
368368
assert (
369-
body["metadata"]["custom"]["vc_generation"]["reasoner_overrides"]["foo"] is False
369+
body["metadata"]["custom"]["vc_generation"]["reasoner_overrides"]["foo"]
370+
is False
370371
)

0 commit comments

Comments
 (0)