Skip to content

Commit 9dbbb0a

Browse files
committed
removed test client method from __main__
1 parent 3df2cba commit 9dbbb0a

File tree

1 file changed

+0
-97
lines changed

1 file changed

+0
-97
lines changed

model-deployment/A2A_agents_on_MD/agent_a/__main__.py

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -151,103 +151,6 @@ async def __call__(self, scope, receive, send):
151151
scope["path"] = "/"
152152
await self.app(scope, receive, send)
153153

154-
# Test Client Function (for standalone testing)
155-
async def test_client_main() -> None:
156-
PUBLIC_AGENT_CARD_PATH = '/.well-known/agent.json'
157-
EXTENDED_AGENT_CARD_PATH = '/agent/authenticatedExtendedCard'
158-
logging.basicConfig(level=logging.INFO)
159-
logger = logging.getLogger(__name__)
160-
161-
base_url = '<add your custom url mdocid url here taken from the invoke your model screen in model deployment console>'
162-
async with httpx.AsyncClient(auth=get_auth(), verify=False, headers={"Content-Length": "0"}) as httpx_client:
163-
resolver = A2ACardResolver(
164-
httpx_client=httpx_client,
165-
base_url=base_url,
166-
)
167-
final_agent_card_to_use: AgentCard | None = None
168-
try:
169-
logger.info(
170-
f'Attempting to fetch public agent card from: {base_url}{PUBLIC_AGENT_CARD_PATH}'
171-
)
172-
_public_card = (
173-
await resolver.get_agent_card()
174-
)
175-
logger.info('Successfully fetched public agent card:')
176-
logger.info(
177-
_public_card.model_dump_json(indent=2, exclude_none=True)
178-
)
179-
final_agent_card_to_use = _public_card
180-
logger.info(
181-
'\nUsing PUBLIC agent card for client initialization (default).'
182-
)
183-
if _public_card.supportsAuthenticatedExtendedCard:
184-
try:
185-
logger.info(
186-
f'\nPublic card supports authenticated extended card. Attempting to fetch from: {base_url}{EXTENDED_AGENT_CARD_PATH}'
187-
)
188-
auth_headers_dict = {
189-
'Authorization': 'Bearer dummy-token-for-extended-card'
190-
}
191-
_extended_card = await resolver.get_agent_card(
192-
relative_card_path=EXTENDED_AGENT_CARD_PATH,
193-
http_kwargs={'headers': auth_headers_dict},
194-
)
195-
logger.info(
196-
'Successfully fetched authenticated extended agent card:'
197-
)
198-
logger.info(
199-
_extended_card.model_dump_json(
200-
indent=2, exclude_none=True
201-
)
202-
)
203-
final_agent_card_to_use = (
204-
_extended_card
205-
)
206-
logger.info(
207-
'\nUsing AUTHENTICATED EXTENDED agent card for client initialization.'
208-
)
209-
except Exception as e_extended:
210-
logger.warning(
211-
f'Failed to fetch extended agent card: {e_extended}. Will proceed with public card.',
212-
exc_info=True,
213-
)
214-
elif (
215-
_public_card
216-
):
217-
logger.info(
218-
'\nPublic card does not indicate support for an extended card. Using public card.'
219-
)
220-
except Exception as e:
221-
logger.error(
222-
f'Critical error fetching public agent card: {e}', exc_info=True
223-
)
224-
raise RuntimeError(
225-
'Failed to fetch the public agent card. Cannot continue.'
226-
) from e
227-
client = A2AClient(
228-
httpx_client=httpx_client, agent_card=final_agent_card_to_use
229-
)
230-
logger.info('A2AClient initialized.')
231-
send_message_payload: dict[str, Any] = {
232-
'message': {
233-
'role': 'user',
234-
'parts': [
235-
{'kind': 'text', 'text': 'how much is 10 USD in INR?'}
236-
],
237-
'messageId': uuid4().hex,
238-
},
239-
}
240-
request = SendMessageRequest(
241-
id=str(uuid4()), params=MessageSendParams(**send_message_payload)
242-
)
243-
response = await client.send_message(request)
244-
print(response.model_dump(mode='json', exclude_none=True))
245-
streaming_request = SendStreamingMessageRequest(
246-
id=str(uuid4()), params=MessageSendParams(**send_message_payload)
247-
)
248-
stream_response = client.send_message_streaming(streaming_request)
249-
async for chunk in stream_response:
250-
print(chunk.model_dump(mode='json', exclude_none=True))
251154

252155
# Main Application
253156
if __name__ == '__main__':

0 commit comments

Comments
 (0)