Skip to content
Merged

Dev #36

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/agentstr/agents/providers/langgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def langgraph_chat_generator(agent: CompiledStateGraph, mcp_clients: list[NostrM
for mcp_client in mcp_clients:
tool_to_sats_map.update(mcp_client.tool_to_sats_map)
async def chat_generator(input: ChatInput) -> AsyncGenerator[ChatOutput, None]:
logger.info(f'Langgraph chat generator input: {input}')
async for chunk in agent.astream(
input={"messages": [{"role": "user", "content": input.message}]},
config={
Expand Down
2 changes: 1 addition & 1 deletion src/agentstr/mcp/nostr_mcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ async def get_skills(self) -> list[Skill]:
"""
return [Skill(name=tool["name"], description=tool["description"]) for tool in (await self.list_tools())["tools"]]

async def call_tool(self, name: str, arguments: dict[str, Any], timeout: int = 60) -> dict[str, Any] | None:
async def call_tool(self, name: str, arguments: dict[str, Any], timeout: int = 120) -> dict[str, Any] | None:
"""Call a tool on the MCP server with provided arguments.

Args:
Expand Down
3 changes: 3 additions & 0 deletions src/agentstr/mcp/nostr_mcp_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ async def _direct_message_callback(self, event: Event, message: str):
logger.debug(f"Request: {message}")
tasks = []
try:
if not message.startswith('{'):
logger.warning(f"Invalid request: {message}. Skipping...")
return
request = json.loads(message)
if request["action"] == "list_tools":
response = await self.list_tools()
Expand Down
4 changes: 2 additions & 2 deletions src/agentstr/nostr_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ async def send_direct_message(self, recipient_pubkey: str, message: str, tags: d
logger.error(f"Failed to send direct message: {e!s}", exc_info=True)
raise

async def receive_direct_message(self, recipient_pubkey: str, timestamp: int | None = None, timeout: int = 60) -> DecryptedMessage | None:
async def receive_direct_message(self, recipient_pubkey: str, timestamp: int | None = None, timeout: int = 120) -> DecryptedMessage | None:
"""Wait for and return the next direct message from a recipient."""
return await self.relay_manager.receive_message(recipient_pubkey, timestamp=timestamp, timeout=timeout)

async def send_direct_message_and_receive_response(self, recipient_pubkey: str, message: str, timeout: int = 60, tags: dict[str, str] | None = None) -> DecryptedMessage:
async def send_direct_message_and_receive_response(self, recipient_pubkey: str, message: str, timeout: int = 120, tags: dict[str, str] | None = None) -> DecryptedMessage:
"""Send an encrypted direct message to a recipient and wait for a response.

Args:
Expand Down
2 changes: 1 addition & 1 deletion src/agentstr/relays/relay.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ async def get_events(self, filters: Filters, limit: int = 10, timeout: int = 30,
pass
return events

async def get_event(self, filters: Filters, timeout: int = 30, close_on_eose: bool = True) -> Event | None:
async def get_event(self, filters: Filters, timeout: int = 120, close_on_eose: bool = True) -> Event | None:
"""Get a single event matching the filters or None if not found."""
events = await self.get_events(filters, limit=1, timeout=timeout, close_on_eose=close_on_eose)
if len(events) > 0:
Expand Down
2 changes: 1 addition & 1 deletion src/agentstr/relays/relay_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def get_events(self, filters: Filters, limit: int = 10, timeout: int = 30,
result = list(event_id_map.values())
return result

async def get_event(self, filters: Filters, timeout: int = 30, close_on_eose: bool = True) -> Event:
async def get_event(self, filters: Filters, timeout: int = 120, close_on_eose: bool = True) -> Event:
"""Get a single event matching the filters or None if not found."""
result = await self.get_events(filters, limit=1, timeout=timeout, close_on_eose=close_on_eose)
if result and len(result) > 0:
Expand Down