-
Notifications
You must be signed in to change notification settings - Fork 72
Optimize delays - realtime, waiting logic and error handling #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c269f89
Optimize EventManager waiting logic and error handling
yarikdevcom 8a48582
perf: pyinstrument integration
yarikdevcom 4f3c3ad
feat: integrate pyinstrument for performance profiling in WebRTC example
yarikdevcom 113ba95
profiling: added implementation as plugin for dev install
yarikdevcom 5c3e662
fix: gemini async client, events base class for start/finish
yarikdevcom de822d2
fix: after rebase
yarikdevcom 10d90f4
fix events flow
yarikdevcom 3ae4fd3
fix: registered events before adding to agent
yarikdevcom 4e8631f
chore: profile.html
yarikdevcom 96f71c7
profile: added example of profiling in simple agent
yarikdevcom 3c5377c
chore: lint
yarikdevcom 540409c
fix: update type hints for async message streaming in GeminiLLM
yarikdevcom 552d809
docs: enhance DEVELOPMENT.md with profiling usage example and update …
yarikdevcom 58d5da4
docs: enhance Profiler class with detailed docstrings for initializat…
yarikdevcom af7d97c
chore: clean up openai_realtime_example.py and update dependencies in…
yarikdevcom ef0313e
refactor: remove unnecessary local variable assignment in GeminiLLM
yarikdevcom 869a253
refactor: update Gemini function calling tests to use new client stru…
yarikdevcom 69194f6
chore: comment out Profiler usage in simple_agent_example.py and prov…
yarikdevcom 57496a9
gemini_llm: fix non-awaited func calls
dangusev 94469f3
gemini_llm: remove type:ignore
dangusev 336fae8
gemini_llm: silence mypy check
dangusev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -85,3 +85,6 @@ stream-py/ | |
| *.pt | ||
| *.kef | ||
| *.onnx | ||
| profile.html | ||
|
|
||
| /opencode.json | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from .base import Profiler | ||
|
|
||
| __all__ = ["Profiler"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import pyinstrument | ||
| import logging | ||
|
|
||
| from vision_agents.core.events import EventManager | ||
| from vision_agents.core.agents import events | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| class Profiler: | ||
| """Profiles agent execution using pyinstrument and generates an HTML report. | ||
|
|
||
| The profiler automatically starts when instantiated and stops when the agent | ||
| finishes (on AgentFinishEvent), saving an HTML performance report to disk. | ||
|
|
||
| Example: | ||
| agent = Agent( | ||
| edge=getstream.Edge(), | ||
| agent_user=User(name="Agent", id="agent"), | ||
| llm=gemini.LLM("gemini-2.0-flash"), | ||
| profiler=Profiler(output_path='./profile.html'), | ||
| ) | ||
| """ | ||
|
|
||
| def __init__(self, output_path='./profile.html'): | ||
| """Initialize the profiler. | ||
|
|
||
| Args: | ||
| output_path: Path where the HTML profile report will be saved. | ||
| Defaults to './profile.html'. | ||
| """ | ||
| self.output_path = output_path | ||
| self.events = EventManager() | ||
| self.events.register_events_from_module(events) | ||
| self.profiler = pyinstrument.Profiler() | ||
| self.profiler.start() | ||
| self.events.subscribe(self.on_finish) | ||
|
|
||
| async def on_finish(self, event: events.AgentFinishEvent): | ||
| """Handle agent finish event by stopping profiler and saving report. | ||
|
|
||
| Args: | ||
| event: The AgentFinishEvent emitted when the agent finishes. | ||
| """ | ||
| self.profiler.stop() | ||
| logger.info(f"Profiler stopped. Time file saved at: {self.output_path}") | ||
| with open(self.output_path, 'w') as f: | ||
| f.write(self.profiler.output_html()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.