|
5 | 5 | """ |
6 | 6 |
|
7 | 7 | import asyncio |
| 8 | +import logging # noqa: F401 |
8 | 9 | import re |
9 | 10 | from collections.abc import AsyncIterator, Sequence |
10 | 11 | from typing import TYPE_CHECKING, Any, Literal, TypedDict |
@@ -323,11 +324,11 @@ async def get_or_create_working_memory( |
323 | 324 | ) |
324 | 325 |
|
325 | 326 | if created: |
326 | | - print("Created new session") |
| 327 | + logging.info("Created new session") |
327 | 328 | else: |
328 | | - print("Found existing session") |
| 329 | + logging.info("Found existing session") |
329 | 330 |
|
330 | | - print(f"Session has {len(memory.messages)} messages") |
| 331 | + logging.info(f"Session has {len(memory.messages)} messages") |
331 | 332 | ``` |
332 | 333 | """ |
333 | 334 | try: |
@@ -638,7 +639,7 @@ async def create_long_term_memory( |
638 | 639 | ] |
639 | 640 |
|
640 | 641 | response = await client.create_long_term_memory(memories) |
641 | | - print(f"Stored memories: {response.status}") |
| 642 | + logging.info(f"Stored memories: {response.status}") |
642 | 643 | ``` |
643 | 644 | """ |
644 | 645 | # Apply default namespace and ensure IDs are present |
@@ -792,9 +793,9 @@ async def search_long_term_memory( |
792 | 793 | distance_threshold=0.3 |
793 | 794 | ) |
794 | 795 |
|
795 | | - print(f"Found {results.total} memories") |
| 796 | + logging.info(f"Found {results.total} memories") |
796 | 797 | for memory in results.memories: |
797 | | - print(f"- {memory.text[:100]}... (distance: {memory.dist})") |
| 798 | + logging.info(f"- {memory.text[:100]}... (distance: {memory.dist})") |
798 | 799 | ``` |
799 | 800 | """ |
800 | 801 | # Convert dictionary filters to their proper filter objects if needed |
@@ -944,9 +945,9 @@ async def search_memory_tool( |
944 | 945 | min_relevance=0.7 |
945 | 946 | ) |
946 | 947 |
|
947 | | - print(result["summary"]) # "Found 2 relevant memories for: user preferences about UI themes" |
| 948 | + logging.info(result["summary"]) # "Found 2 relevant memories for: user preferences about UI themes" |
948 | 949 | for memory in result["memories"]: |
949 | | - print(f"- {memory['text']} (score: {memory['relevance_score']})") |
| 950 | + logging.info(f"- {memory['text']} (score: {memory['relevance_score']})") |
950 | 951 | ``` |
951 | 952 |
|
952 | 953 | LLM Framework Integration: |
@@ -1147,9 +1148,9 @@ async def get_working_memory_tool( |
1147 | 1148 | session_id="current_session" |
1148 | 1149 | ) |
1149 | 1150 |
|
1150 | | - print(memory_state["summary"]) # Human-readable summary |
1151 | | - print(f"Messages: {memory_state['message_count']}") |
1152 | | - print(f"Memories: {len(memory_state['memories'])}") |
| 1151 | + logging.info(memory_state["summary"]) # Human-readable summary |
| 1152 | + logging.info(f"Messages: {memory_state['message_count']}") |
| 1153 | + logging.info(f"Memories: {len(memory_state['memories'])}") |
1153 | 1154 | ``` |
1154 | 1155 | """ |
1155 | 1156 | try: |
@@ -1227,13 +1228,13 @@ async def get_or_create_working_memory_tool( |
1227 | 1228 | ) |
1228 | 1229 |
|
1229 | 1230 | if memory_state["created"]: |
1230 | | - print("Created new session") |
| 1231 | + logging.info("Created new session") |
1231 | 1232 | else: |
1232 | | - print("Found existing session") |
| 1233 | + logging.info("Found existing session") |
1233 | 1234 |
|
1234 | | - print(memory_state["summary"]) # Human-readable summary |
1235 | | - print(f"Messages: {memory_state['message_count']}") |
1236 | | - print(f"Memories: {len(memory_state['memories'])}") |
| 1235 | + logging.info(memory_state["summary"]) # Human-readable summary |
| 1236 | + logging.info(f"Messages: {memory_state['message_count']}") |
| 1237 | + logging.info(f"Memories: {len(memory_state['memories'])}") |
1237 | 1238 | ``` |
1238 | 1239 | """ |
1239 | 1240 | try: |
@@ -1325,7 +1326,7 @@ async def add_memory_tool( |
1325 | 1326 | entities=["vegetarian", "restaurants"] |
1326 | 1327 | ) |
1327 | 1328 |
|
1328 | | - print(result["summary"]) # "Successfully stored semantic memory" |
| 1329 | + logging.info(result["summary"]) # "Successfully stored semantic memory" |
1329 | 1330 | ``` |
1330 | 1331 | """ |
1331 | 1332 | try: |
@@ -1399,7 +1400,7 @@ async def update_memory_data_tool( |
1399 | 1400 | } |
1400 | 1401 | ) |
1401 | 1402 |
|
1402 | | - print(result["summary"]) # "Successfully updated 3 data entries" |
| 1403 | + logging.info(result["summary"]) # "Successfully updated 3 data entries" |
1403 | 1404 | ``` |
1404 | 1405 | """ |
1405 | 1406 | try: |
@@ -1974,9 +1975,9 @@ async def resolve_tool_call( |
1974 | 1975 | ) |
1975 | 1976 |
|
1976 | 1977 | if result["success"]: |
1977 | | - print(result["formatted_response"]) |
| 1978 | + logging.info(result["formatted_response"]) |
1978 | 1979 | else: |
1979 | | - print(f"Error: {result['error']}") |
| 1980 | + logging.error(f"Error: {result['error']}") |
1980 | 1981 | ``` |
1981 | 1982 | """ |
1982 | 1983 | try: |
@@ -2030,7 +2031,7 @@ async def resolve_tool_calls( |
2030 | 2031 |
|
2031 | 2032 | for result in results: |
2032 | 2033 | if result["success"]: |
2033 | | - print(f"{result['function_name']}: {result['formatted_response']}") |
| 2034 | + logging.info(f"{result['function_name']}: {result['formatted_response']}") |
2034 | 2035 | ``` |
2035 | 2036 | """ |
2036 | 2037 | results = [] |
@@ -2088,9 +2089,9 @@ async def resolve_function_call( |
2088 | 2089 | ) |
2089 | 2090 |
|
2090 | 2091 | if result["success"]: |
2091 | | - print(result["formatted_response"]) |
| 2092 | + logging.info(result["formatted_response"]) |
2092 | 2093 | else: |
2093 | | - print(f"Error: {result['error']}") |
| 2094 | + logging.error(f"Error: {result['error']}") |
2094 | 2095 | ``` |
2095 | 2096 | """ |
2096 | 2097 | import json |
@@ -2378,7 +2379,7 @@ async def resolve_function_calls( |
2378 | 2379 | results = await client.resolve_function_calls(calls, "session123") |
2379 | 2380 | for result in results: |
2380 | 2381 | if result["success"]: |
2381 | | - print(f"{result['function_name']}: {result['formatted_response']}") |
| 2382 | + logging.info(f"{result['function_name']}: {result['formatted_response']}") |
2382 | 2383 | ``` |
2383 | 2384 | """ |
2384 | 2385 | results = [] |
|
0 commit comments