-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add Agno framework integration #25
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
Closed
Closed
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a46bf39
chore: release 0.3.0
ryoppippi 5eff322
feat: add Agno framework integration
ryoppippi 8544d2e
fix: correct Agno Agent import path for v1.7.11
ryoppippi 4581393
fix: update Agno integration for v1.7.11 architecture
ryoppippi 24b2a3c
ENG-10863
ryoppippi d22aa27
Merge branch 'main' into feat/agno-integration
ryoppippi 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
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
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,119 @@ | ||
| """ | ||
| This example demonstrates how to use StackOne tools with Agno agents. | ||
|
|
||
| This example is runnable with the following command: | ||
| ```bash | ||
| uv run examples/agno_integration.py | ||
| ``` | ||
|
|
||
| You can find out more about Agno framework at https://docs.agno.com | ||
| """ | ||
|
|
||
| from agno import Agent | ||
| from agno.models.openai import OpenAIChat | ||
| from dotenv import load_dotenv | ||
|
|
||
| from stackone_ai import StackOneToolSet | ||
|
|
||
| load_dotenv() | ||
|
|
||
| account_id = "45072196112816593343" | ||
| employee_id = "c28xIQaWQ6MzM5MzczMDA2NzMzMzkwNzIwNA" | ||
|
|
||
|
|
||
| def agno_integration() -> None: | ||
| """Demonstrate StackOne tools with Agno agents""" | ||
| toolset = StackOneToolSet() | ||
|
|
||
| # Filter tools to only the ones we need to avoid context window limits | ||
| tools = toolset.get_tools( | ||
| [ | ||
| "hris_get_employee", | ||
| "hris_list_employee_employments", | ||
| "hris_get_employee_employment", | ||
| ], | ||
| account_id=account_id, | ||
| ) | ||
|
|
||
| # Convert to Agno format | ||
| agno_tools = tools.to_agno() | ||
|
|
||
| # Create an Agno agent with the tools | ||
| agent = Agent( | ||
| name="HR Assistant Agent", | ||
| role="Helpful HR assistant that can access employee data", | ||
| model=OpenAIChat(id="gpt-4o-mini"), | ||
| tools=agno_tools, | ||
| instructions=[ | ||
| "You are a helpful HR assistant.", | ||
| "Use the provided tools to access employee information.", | ||
| "Always be professional and respectful when handling employee data.", | ||
| ], | ||
| show_tool_calls=True, | ||
| markdown=True, | ||
| ) | ||
|
|
||
| # Test the agent with a query | ||
| query = f"Can you get me information about employee with ID: {employee_id}?" | ||
|
|
||
| print(f"Query: {query}") | ||
| print("Agent response:") | ||
|
|
||
| response = agent.run(query) | ||
| print(response.content) | ||
|
|
||
| # Verify we got a meaningful response | ||
| assert response.content is not None, "Expected response content" | ||
| assert len(response.content) > 0, "Expected non-empty response" | ||
|
|
||
|
|
||
| def agno_async_integration() -> None: | ||
| """Demonstrate async StackOne tools with Agno agents""" | ||
| import asyncio | ||
|
|
||
| async def run_async_agent() -> None: | ||
| toolset = StackOneToolSet() | ||
|
|
||
| # Filter tools to only the ones we need | ||
| tools = toolset.get_tools( | ||
| ["hris_get_employee"], | ||
| account_id=account_id, | ||
| ) | ||
|
|
||
| # Convert to Agno format | ||
| agno_tools = tools.to_agno() | ||
|
|
||
| # Create an Agno agent | ||
| agent = Agent( | ||
| name="Async HR Agent", | ||
| role="Async HR assistant", | ||
| model=OpenAIChat(id="gpt-4o-mini"), | ||
| tools=agno_tools, | ||
| instructions=["You are an async HR assistant."], | ||
| ) | ||
|
|
||
| # Run the agent asynchronously | ||
| query = f"Get employee information for ID: {employee_id}" | ||
| response = await agent.arun(query) | ||
|
|
||
| print(f"Async query: {query}") | ||
| print("Async agent response:") | ||
| print(response.content) | ||
|
|
||
| # Verify response | ||
| assert response.content is not None, "Expected async response content" | ||
|
|
||
| # Run the async example | ||
| asyncio.run(run_async_agent()) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| print("=== StackOne + Agno Integration Demo ===\n") | ||
|
|
||
| print("1. Basic Agno Integration:") | ||
| agno_integration() | ||
|
|
||
| print("\n2. Async Agno Integration:") | ||
| agno_async_integration() | ||
|
|
||
| print("\n=== Demo completed successfully! ===") | ||
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,164 @@ | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| from stackone_ai.models import ( | ||
| ExecuteConfig, | ||
| StackOneTool, | ||
| ToolParameters, | ||
| Tools, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def mock_tool() -> StackOneTool: | ||
| """Create a mock tool for testing""" | ||
| return StackOneTool( | ||
| description="Test HRIS tool for getting employee data", | ||
| parameters=ToolParameters( | ||
| type="object", | ||
| properties={ | ||
| "id": {"type": "string", "description": "Employee ID"}, | ||
| "include_personal": {"type": "boolean", "description": "Include personal information"}, | ||
| }, | ||
| ), | ||
| _execute_config=ExecuteConfig( | ||
| headers={}, | ||
| method="GET", | ||
| url="https://api.stackone.com/unified/hris/employees/{id}", | ||
| name="hris_get_employee", | ||
| parameter_locations={"id": "path"}, | ||
| ), | ||
| _api_key="test_key", | ||
| _account_id="test_account", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def tools_collection(mock_tool: StackOneTool) -> Tools: | ||
| """Create a Tools collection with mock tools""" | ||
| return Tools([mock_tool]) | ||
|
|
||
|
|
||
| class TestAgnoIntegration: | ||
| """Test Agno integration functionality""" | ||
|
|
||
| def test_to_agno_without_agno_installed(self, mock_tool: StackOneTool) -> None: | ||
| """Test that proper error is raised when Agno is not installed""" | ||
| with patch.dict('sys.modules', {'agno': None, 'agno.tools': None}): | ||
| with pytest.raises(ImportError) as exc_info: | ||
| mock_tool.to_agno() | ||
|
|
||
| assert "Agno is not installed" in str(exc_info.value) | ||
| assert "pip install agno>=1.7.0" in str(exc_info.value) | ||
|
|
||
| def test_to_agno_with_mocked_agno(self, mock_tool: StackOneTool) -> None: | ||
| """Test Agno conversion with mocked Agno classes""" | ||
| # Mock the Agno Tool class | ||
| mock_agno_base_tool = MagicMock() | ||
|
||
| mock_agno_module = MagicMock() | ||
| mock_agno_module.Tool = mock_agno_base_tool | ||
|
|
||
| with patch.dict('sys.modules', {'agno.tools': mock_agno_module}): | ||
| agno_tool = mock_tool.to_agno() | ||
|
|
||
| # Verify an Agno tool instance was created | ||
| assert agno_tool is not None | ||
|
|
||
| def test_to_agno_tool_execution(self, mock_tool: StackOneTool) -> None: | ||
| """Test that the Agno tool can execute the underlying StackOne tool""" | ||
| mock_agno_base_tool = MagicMock() | ||
| mock_agno_module = MagicMock() | ||
| mock_agno_module.Tool = mock_agno_base_tool | ||
|
|
||
| with patch.dict('sys.modules', {'agno.tools': mock_agno_module}): | ||
| agno_tool = mock_tool.to_agno() | ||
|
|
||
| # Verify the tool was created (basic functionality test) | ||
| assert agno_tool is not None | ||
| assert hasattr(agno_tool, 'run') | ||
|
|
||
| def test_tools_to_agno(self, tools_collection: Tools) -> None: | ||
| """Test converting Tools collection to Agno format""" | ||
| mock_agno_base_tool = MagicMock() | ||
| mock_agno_module = MagicMock() | ||
| mock_agno_module.Tool = mock_agno_base_tool | ||
|
|
||
| with patch.dict('sys.modules', {'agno.tools': mock_agno_module}): | ||
| agno_tools = tools_collection.to_agno() | ||
|
|
||
| # Verify we got the expected number of tools | ||
| assert len(agno_tools) == 1 | ||
| assert agno_tools[0] is not None | ||
|
|
||
| def test_tools_to_agno_multiple_tools(self) -> None: | ||
| """Test converting multiple tools to Agno format""" | ||
| # Create multiple mock tools | ||
| tool1 = StackOneTool( | ||
| description="Test tool 1", | ||
| parameters=ToolParameters(type="object", properties={"id": {"type": "string"}}), | ||
| _execute_config=ExecuteConfig( | ||
| headers={}, method="GET", url="https://api.example.com/test1/{id}", name="test_tool_1" | ||
| ), | ||
| _api_key="test_key", | ||
| ) | ||
| tool2 = StackOneTool( | ||
| description="Test tool 2", | ||
| parameters=ToolParameters(type="object", properties={"name": {"type": "string"}}), | ||
| _execute_config=ExecuteConfig( | ||
| headers={}, method="POST", url="https://api.example.com/test2", name="test_tool_2" | ||
| ), | ||
| _api_key="test_key", | ||
| ) | ||
|
|
||
| tools = Tools([tool1, tool2]) | ||
|
|
||
| mock_agno_base_tool = MagicMock() | ||
| mock_agno_module = MagicMock() | ||
| mock_agno_module.Tool = mock_agno_base_tool | ||
|
|
||
| with patch.dict('sys.modules', {'agno.tools': mock_agno_module}): | ||
| agno_tools = tools.to_agno() | ||
|
|
||
| assert len(agno_tools) == 2 | ||
| assert all(tool is not None for tool in agno_tools) | ||
|
|
||
| def test_agno_tool_preserves_metadata(self, mock_tool: StackOneTool) -> None: | ||
| """Test that Agno tool conversion preserves important metadata""" | ||
| mock_agno_base_tool = MagicMock() | ||
| mock_agno_module = MagicMock() | ||
| mock_agno_module.Tool = mock_agno_base_tool | ||
|
|
||
| with patch.dict('sys.modules', {'agno.tools': mock_agno_module}): | ||
| agno_tool = mock_tool.to_agno() | ||
|
|
||
| # Verify the tool was created with expected attributes | ||
| assert agno_tool is not None | ||
| # For real integration, name and description would be set by the Agno base class | ||
| assert hasattr(agno_tool, 'name') | ||
| assert hasattr(agno_tool, 'description') | ||
|
|
||
|
|
||
| class TestAgnoIntegrationErrors: | ||
| """Test error handling in Agno integration""" | ||
|
|
||
| def test_agno_import_error_message(self, mock_tool: StackOneTool) -> None: | ||
| """Test that ImportError contains helpful installation instructions""" | ||
| with patch.dict('sys.modules', {'agno': None, 'agno.tools': None}): | ||
| with pytest.raises(ImportError) as exc_info: | ||
| mock_tool.to_agno() | ||
|
|
||
| error_msg = str(exc_info.value) | ||
| assert "Agno is not installed" in error_msg | ||
| assert "pip install agno>=1.7.0" in error_msg | ||
| assert "requirements" in error_msg | ||
|
|
||
| def test_tools_to_agno_with_failed_conversion(self) -> None: | ||
| """Test Tools.to_agno() when individual tool conversion fails""" | ||
| mock_tool = MagicMock() | ||
| mock_tool.to_agno.side_effect = ImportError("Agno not available") | ||
|
|
||
| tools = Tools([mock_tool]) | ||
|
|
||
| with pytest.raises(ImportError): | ||
| tools.to_agno() | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid hard-coding potentially sensitive account and employee identifiers; read them from environment variables or user input instead.
Prompt for AI agents