今天我們通過來拆strandsagents官網的一個例子來學習strandsagents的http_request tool
https://strandsagents.com/latest/documentation/docs/examples/python/agents_workflows/
看上去能做實事核查,實際上沒那么高大上。
Show me the code
https://github.com/strands-agents/tools/blob/main/src/strands_tools/http_request.py#L546
實際上最后調用的是
https://github.com/strands-agents/tools/blob/main/src/strands_tools/http_request.py#L220
通過Python自帶的request.Session實例的response = session.request(**request_kwargs)方法來進行請求。
request.Session
- 它是什么?
requests.Session() 用于創建一個會話對象(Session Object)。你可以把這個會話想象成一個小型的、可持續的瀏覽器窗口。
通常,當你直接使用 requests.get() 或 requests.post() 時,每個請求都是獨立、無狀態的。它們之間互不相識,就像你每次都用不同的瀏覽器標簽頁訪問網站一樣。
而 Sess