1. **Issue**: When calling `list_agent_session` via the HTTP API, users may only need to display conversation messages, and do not want to see the associated dsl, which can be very large. Therefore, consider adding a control option to determine whether the DSL should be returned, with the default being to return it. 2. **Documentation Discrepancy**: In the HTTP API documentation, under "List agent sessions," the "Response" section states that the "data" field is a dictionary when "success" is returned. However, the actual returned data is a list. This discrepancy has been corrected.tags/v0.17.1
| desc = False | desc = False | ||||
| else: | else: | ||||
| desc = True | desc = True | ||||
| convs = API4ConversationService.get_list(agent_id, tenant_id, page_number, items_per_page, orderby, desc, id, user_id) | |||||
| # dsl defaults to True in all cases except for False and false | |||||
| include_dsl = request.args.get("dsl") != "False" and request.args.get("dsl") != "false" | |||||
| convs = API4ConversationService.get_list(agent_id, tenant_id, page_number, items_per_page, orderby, desc, id, | |||||
| user_id, include_dsl) | |||||
| if not convs: | if not convs: | ||||
| return get_result(data=[]) | return get_result(data=[]) | ||||
| for conv in convs: | for conv in convs: |
| @DB.connection_context() | @DB.connection_context() | ||||
| def get_list(cls, dialog_id, tenant_id, | def get_list(cls, dialog_id, tenant_id, | ||||
| page_number, items_per_page, | page_number, items_per_page, | ||||
| orderby, desc, id, user_id=None): | |||||
| sessions = cls.model.select().where(cls.model.dialog_id == dialog_id) | |||||
| orderby, desc, id, user_id=None, include_dsl=True): | |||||
| if include_dsl: | |||||
| sessions = cls.model.select().where(cls.model.dialog_id == dialog_id) | |||||
| else: | |||||
| fields = [field for field in cls.model._meta.fields.values() if field.name != 'dsl'] | |||||
| sessions = cls.model.select(*fields).where(cls.model.dialog_id == dialog_id) | |||||
| if id: | if id: | ||||
| sessions = sessions.where(cls.model.id == id) | sessions = sessions.where(cls.model.id == id) | ||||
| if user_id: | if user_id: |
| ### List agent sessions | ### List agent sessions | ||||
| **GET** `/api/v1/agents/{agent_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&id={session_id}&user_id={user_id}` | |||||
| **GET** `/api/v1/agents/{agent_id}/sessions?page={page}&page_size={page_size}&orderby={orderby}&desc={desc}&id={session_id}&user_id={user_id}&dsl={dsl}` | |||||
| Lists sessions associated with a specified agent. | Lists sessions associated with a specified agent. | ||||
| The ID of the agent session to retrieve. | The ID of the agent session to retrieve. | ||||
| - `user_id`: (*Filter parameter*), `string` | - `user_id`: (*Filter parameter*), `string` | ||||
| The optional user-defined ID passed in when creating session. | The optional user-defined ID passed in when creating session. | ||||
| - `dsl`: (*Filter parameter*), `boolean` | |||||
| Indicates whether to include the dsl field of the sessions in the response. Defaults to `true`. | |||||
| #### Response | #### Response | ||||
| Success: | Success: | ||||
| ```json | ```json | ||||
| { | { | ||||
| "code": 0, | "code": 0, | ||||
| "data": { | |||||
| "data": [{ | |||||
| "agent_id": "e9e2b9c2b2f911ef801d0242ac120006", | "agent_id": "e9e2b9c2b2f911ef801d0242ac120006", | ||||
| "dsl": { | "dsl": { | ||||
| "answer": [], | "answer": [], | ||||
| ], | ], | ||||
| "source": "agent", | "source": "agent", | ||||
| "user_id": "" | "user_id": "" | ||||
| } | |||||
| }] | |||||
| } | } | ||||
| ``` | ``` | ||||