Skip to content

Commit ab32094

Browse files
flake8 & black
1 parent 627a6f1 commit ab32094

File tree

3 files changed

+191
-168
lines changed

3 files changed

+191
-168
lines changed

atomic-agents/atomic_agents/agents/atomic_agent.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import instructor
22
from pydantic import BaseModel, Field
3-
from typing import Optional, Type, Generator, AsyncGenerator, get_args, Dict, List, Callable, Any
3+
from typing import Optional, Type, Generator, AsyncGenerator, get_args, Dict, List, Callable
44
import logging
55
from atomic_agents.context.chat_history import ChatHistory
66
from atomic_agents.context.system_prompt_generator import (
@@ -98,13 +98,13 @@ class AtomicAgent[InputSchema: BaseIOSchema, OutputSchema: BaseIOSchema]:
9898
Hook System:
9999
The AtomicAgent integrates with Instructor's hook system to provide comprehensive monitoring
100100
and error handling capabilities. Supported events include:
101-
101+
102102
- 'parse:error': Triggered when Pydantic validation fails
103-
- 'completion:kwargs': Triggered before completion request
103+
- 'completion:kwargs': Triggered before completion request
104104
- 'completion:response': Triggered after completion response
105105
- 'completion:error': Triggered on completion errors
106106
- 'completion:last_attempt': Triggered on final retry attempt
107-
107+
108108
Hook Methods:
109109
- register_hook(event, handler): Register a hook handler for an event
110110
- unregister_hook(event, handler): Remove a hook handler
@@ -116,14 +116,14 @@ class AtomicAgent[InputSchema: BaseIOSchema, OutputSchema: BaseIOSchema]:
116116
```python
117117
# Basic usage
118118
agent = AtomicAgent[InputSchema, OutputSchema](config)
119-
119+
120120
# Register parse error hook for intelligent retry handling
121121
def handle_parse_error(error):
122122
print(f"Validation failed: {error}")
123123
# Implement custom retry logic, logging, etc.
124-
124+
125125
agent.register_hook("parse:error", handle_parse_error)
126-
126+
127127
# Now parse:error hooks will fire on validation failures
128128
response = agent.run(user_input)
129129
```
@@ -144,7 +144,7 @@ def __init__(self, config: AgentConfig):
144144
self.initial_history = self.history.copy()
145145
self.current_user_input = None
146146
self.model_api_parameters = config.model_api_parameters or {}
147-
147+
148148
# Hook management attributes
149149
self._hook_handlers: Dict[str, List[Callable]] = {}
150150
self._hooks_enabled: bool = True
@@ -361,65 +361,65 @@ def unregister_context_provider(self, provider_name: str):
361361
def register_hook(self, event: str, handler: Callable) -> None:
362362
"""
363363
Registers a hook handler for a specific event.
364-
364+
365365
Args:
366366
event (str): The event name (e.g., 'parse:error', 'completion:kwargs', etc.)
367367
handler (Callable): The callback function to handle the event
368368
"""
369369
if event not in self._hook_handlers:
370370
self._hook_handlers[event] = []
371371
self._hook_handlers[event].append(handler)
372-
372+
373373
# Register with instructor client if it supports hooks
374-
if hasattr(self.client, 'on'):
374+
if hasattr(self.client, "on"):
375375
self.client.on(event, handler)
376376

377377
def unregister_hook(self, event: str, handler: Callable) -> None:
378378
"""
379379
Unregisters a hook handler for a specific event.
380-
380+
381381
Args:
382382
event (str): The event name
383383
handler (Callable): The callback function to remove
384384
"""
385385
if event in self._hook_handlers and handler in self._hook_handlers[event]:
386386
self._hook_handlers[event].remove(handler)
387-
387+
388388
# Remove from instructor client if it supports hooks
389-
if hasattr(self.client, 'off'):
389+
if hasattr(self.client, "off"):
390390
self.client.off(event, handler)
391391

392392
def clear_hooks(self, event: Optional[str] = None) -> None:
393393
"""
394394
Clears hook handlers for a specific event or all events.
395-
395+
396396
Args:
397397
event (Optional[str]): The event name to clear, or None to clear all
398398
"""
399399
if event:
400400
if event in self._hook_handlers:
401401
# Clear from instructor client first
402-
if hasattr(self.client, 'clear'):
402+
if hasattr(self.client, "clear"):
403403
self.client.clear(event)
404404
self._hook_handlers[event].clear()
405405
else:
406406
# Clear all hooks
407-
if hasattr(self.client, 'clear'):
407+
if hasattr(self.client, "clear"):
408408
self.client.clear()
409409
self._hook_handlers.clear()
410410

411411
def _dispatch_hook(self, event: str, *args, **kwargs) -> None:
412412
"""
413413
Internal method to dispatch hook events with error isolation.
414-
414+
415415
Args:
416416
event (str): The event name
417417
*args: Arguments to pass to handlers
418418
**kwargs: Keyword arguments to pass to handlers
419419
"""
420420
if not self._hooks_enabled or event not in self._hook_handlers:
421421
return
422-
422+
423423
for handler in self._hook_handlers[event]:
424424
try:
425425
handler(*args, **kwargs)

0 commit comments

Comments
 (0)