tinyagent-py 0.0.5__py3-none-any.whl → 0.0.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tinyagent/mcp_client.py +0 -5
- tinyagent/tiny_agent.py +49 -4
- {tinyagent_py-0.0.5.dist-info → tinyagent_py-0.0.6.dist-info}/METADATA +1 -1
- {tinyagent_py-0.0.5.dist-info → tinyagent_py-0.0.6.dist-info}/RECORD +7 -7
- {tinyagent_py-0.0.5.dist-info → tinyagent_py-0.0.6.dist-info}/WHEEL +0 -0
- {tinyagent_py-0.0.5.dist-info → tinyagent_py-0.0.6.dist-info}/licenses/LICENSE +0 -0
- {tinyagent_py-0.0.5.dist-info → tinyagent_py-0.0.6.dist-info}/top_level.txt +0 -0
tinyagent/mcp_client.py
CHANGED
@@ -106,11 +106,6 @@ class MCPClient:
|
|
106
106
|
|
107
107
|
async def close(self):
|
108
108
|
"""Clean up subprocess and streams."""
|
109
|
-
if self.session:
|
110
|
-
try:
|
111
|
-
await self.session.close()
|
112
|
-
except Exception as e:
|
113
|
-
self.logger.error(f"Error closing session: {e}")
|
114
109
|
if self.exit_stack:
|
115
110
|
try:
|
116
111
|
await self.exit_stack.aclose()
|
tinyagent/tiny_agent.py
CHANGED
@@ -746,13 +746,58 @@ class TinyAgent:
|
|
746
746
|
|
747
747
|
|
748
748
|
async def close(self):
|
749
|
-
"""
|
749
|
+
"""
|
750
|
+
Clean up all resources used by the agent including MCP clients and storage.
|
751
|
+
|
752
|
+
This method should be called when the agent is no longer needed to ensure
|
753
|
+
proper resource cleanup, especially in web frameworks like FastAPI.
|
754
|
+
"""
|
755
|
+
cleanup_errors = []
|
756
|
+
|
757
|
+
# 1. First save any pending state if storage is configured
|
758
|
+
if self.storage:
|
759
|
+
try:
|
760
|
+
self.logger.debug(f"Saving final state before closing (session={self.session_id})")
|
761
|
+
await self.save_agent()
|
762
|
+
except Exception as e:
|
763
|
+
error_msg = f"Error saving final state: {str(e)}"
|
764
|
+
self.logger.error(error_msg)
|
765
|
+
cleanup_errors.append(error_msg)
|
766
|
+
|
767
|
+
# 2. Close all MCP clients
|
750
768
|
for client in self.mcp_clients:
|
751
769
|
try:
|
770
|
+
self.logger.debug(f"Closing MCP client: {client}")
|
752
771
|
await client.close()
|
753
|
-
except
|
754
|
-
|
755
|
-
|
772
|
+
except Exception as e:
|
773
|
+
error_msg = f"Error closing MCP client: {str(e)}"
|
774
|
+
self.logger.error(error_msg)
|
775
|
+
cleanup_errors.append(error_msg)
|
776
|
+
|
777
|
+
# 3. Close storage connection if available
|
778
|
+
if self.storage:
|
779
|
+
try:
|
780
|
+
self.logger.debug("Closing storage connection")
|
781
|
+
await self.storage.close()
|
782
|
+
except Exception as e:
|
783
|
+
error_msg = f"Error closing storage: {str(e)}"
|
784
|
+
self.logger.error(error_msg)
|
785
|
+
cleanup_errors.append(error_msg)
|
786
|
+
|
787
|
+
# 4. Run any cleanup callbacks
|
788
|
+
try:
|
789
|
+
await self._run_callbacks("agent_cleanup")
|
790
|
+
except Exception as e:
|
791
|
+
error_msg = f"Error in cleanup callbacks: {str(e)}"
|
792
|
+
self.logger.error(error_msg)
|
793
|
+
cleanup_errors.append(error_msg)
|
794
|
+
|
795
|
+
# Log summary of cleanup
|
796
|
+
if cleanup_errors:
|
797
|
+
self.logger.warning(f"TinyAgent cleanup completed with {len(cleanup_errors)} errors")
|
798
|
+
else:
|
799
|
+
self.logger.info(f"TinyAgent cleanup completed successfully (session={self.session_id})")
|
800
|
+
|
756
801
|
def clear_conversation(self):
|
757
802
|
"""
|
758
803
|
Clear the conversation history, preserving only the initial system prompt.
|
@@ -1,6 +1,6 @@
|
|
1
1
|
tinyagent/__init__.py,sha256=GrD21npMQGzl9ZYKYTP8VxHLzCfJCvA0oTKQZTkmnCw,117
|
2
|
-
tinyagent/mcp_client.py,sha256=
|
3
|
-
tinyagent/tiny_agent.py,sha256=
|
2
|
+
tinyagent/mcp_client.py,sha256=9dmLtJ8CTwKWKTH6K9z8CaCQuaicOH9ifAuNyX7Kdo0,6030
|
3
|
+
tinyagent/tiny_agent.py,sha256=PW_mY0uqKqzVN3ANWauF0RmvXNobR_EoPjGv40m1oKw,41074
|
4
4
|
tinyagent/hooks/__init__.py,sha256=UztCHjoqF5JyDolbWwkBsBZkWguDQg23l2GD_zMHt-s,178
|
5
5
|
tinyagent/hooks/agno_storage_hook.py,sha256=5qvvjmtraanPa-A46Zstrqq3s1e-sC7Ly0o3zifuw_4,5003
|
6
6
|
tinyagent/hooks/gradio_callback.py,sha256=jGsZlObAd6I5lN9cE53dDL_LfiB8I0tBsicuHwwmL-M,44833
|
@@ -13,8 +13,8 @@ tinyagent/storage/json_file_storage.py,sha256=SYD8lvTHu2-FEHm1tZmsrcgEOirBrlUsUM
|
|
13
13
|
tinyagent/storage/postgres_storage.py,sha256=IGwan8UXHNnTZFK1F8x4kvMDex3GAAGWUg9ePx_5IF4,9018
|
14
14
|
tinyagent/storage/redis_storage.py,sha256=hu3y7wHi49HkpiR-AW7cWVQuTVOUk1WaB8TEPGUKVJ8,1742
|
15
15
|
tinyagent/storage/sqlite_storage.py,sha256=7lk1XZpr2t4s2bjVr9-AqrI74w4hwkuK3taWtyJZhBc,5769
|
16
|
-
tinyagent_py-0.0.
|
17
|
-
tinyagent_py-0.0.
|
18
|
-
tinyagent_py-0.0.
|
19
|
-
tinyagent_py-0.0.
|
20
|
-
tinyagent_py-0.0.
|
16
|
+
tinyagent_py-0.0.6.dist-info/licenses/LICENSE,sha256=YIogcVQnknaaE4K-oaQylFWo8JGRBWnwmGb3fWB_Pww,1064
|
17
|
+
tinyagent_py-0.0.6.dist-info/METADATA,sha256=rL8hpf-PC0CBRcoyDEe71okWlzLi9SEln03ZHRs_ikI,9054
|
18
|
+
tinyagent_py-0.0.6.dist-info/WHEEL,sha256=zaaOINJESkSfm_4HQVc5ssNzHCPXhJm0kEUakpsEHaU,91
|
19
|
+
tinyagent_py-0.0.6.dist-info/top_level.txt,sha256=Ny8aJNchZpc2Vvhp3306L5vjceJakvFxBk-UjjVeA_I,10
|
20
|
+
tinyagent_py-0.0.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|