diff --git a/agentlego/tools/remote.py b/agentlego/tools/remote.py index 89ad8521..99789b4b 100644 --- a/agentlego/tools/remote.py +++ b/agentlego/tools/remote.py @@ -145,6 +145,12 @@ def apply(self, *args, **kwargs): content = response.content.decode() raise RuntimeError(f'Failed to call the remote tool `{self.name}` ' f'because of {response.reason}.\nResponse: {content}') + + response_schema = self.operation.responses + if response_schema is None or response_schema.get('200') is None: + # Directly use string if the response schema is not specified + return response.text + try: response = response.json() except requests.JSONDecodeError as e: @@ -152,11 +158,6 @@ def apply(self, *args, **kwargs): 'because of unknown response.\n' f'Response: {response.content.decode()}') from e - response_schema = self.operation.responses - if response_schema is None or response_schema.get('200') is None: - # Directly use string if the response schema is not specified - return str(response) - out_props = response_schema['200'].properties if isinstance(out_props, APIResponseProperty): diff --git a/agentlego/utils/openapi/api_model.py b/agentlego/utils/openapi/api_model.py index 2b7a2a82..1e14300f 100644 --- a/agentlego/utils/openapi/api_model.py +++ b/agentlego/utils/openapi/api_model.py @@ -498,8 +498,11 @@ def _process_supported_media_type( return properties @classmethod - def from_response(cls, response: Response, spec: OpenAPISpec) -> 'APIResponse': + def from_response(cls, response: Response, + spec: OpenAPISpec) -> Optional['APIResponse']: """Instantiate from an OpenAPI Response.""" + if response.content is None: + return None # Only handle one potential response payload style. media_type = next( (k for k in response.content if k in _SUPPORTED_RESPONSE_MEDIA_TYPES), None) @@ -545,7 +548,7 @@ class APIOperation(BaseModel): request_body: Optional[APIRequestBody] = Field(alias='request_body') """The request body of the operation.""" - responses: Optional[Dict[str, APIResponse]] = Field(alias='responses') + responses: Optional[Dict[str, Optional[APIResponse]]] = Field(alias='responses') @staticmethod def _get_properties_from_parameters(parameters: List[Parameter],