001/*
002 *  Copyright (c) 2023-2026, Agents-Flex (fuhai999@gmail.com).
003 *  <p>
004 *  Licensed under the Apache License, Version 2.0 (the "License");
005 *  you may not use this file except in compliance with the License.
006 *  You may obtain a copy of the License at
007 *  <p>
008 *  http://www.apache.org/licenses/LICENSE-2.0
009 *  <p>
010 *  Unless required by applicable law or agreed to in writing, software
011 *  distributed under the License is distributed on an "AS IS" BASIS,
012 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 *  See the License for the specific language governing permissions and
014 *  limitations under the License.
015 */
016package com.agentsflex.core.model.chat.tool;
017
018import com.agentsflex.core.message.ToolCall;
019
020import java.io.Serializable;
021import java.util.HashMap;
022import java.util.Map;
023
024/**
025 * 函数调用上下文,贯穿整个拦截链。
026 */
027public class ToolContext implements Serializable {
028    private final Tool tool;
029    private final ToolCall toolCall;
030    private final Map<String, Object> attributes = new HashMap<>();
031
032
033    public ToolContext(Tool tool, ToolCall toolCall) {
034        this.tool = tool;
035        this.toolCall = toolCall;
036    }
037
038    public Tool getTool() {
039        return tool;
040    }
041
042    public ToolCall getToolCall() {
043        return toolCall;
044    }
045
046    public Map<String, Object> getArgsMap() {
047        return toolCall.getArgsMap();
048    }
049
050
051    public void setAttribute(String key, Object value) {
052        attributes.put(key, value);
053    }
054
055    @SuppressWarnings("unchecked")
056    public <T> T getAttribute(String key) {
057        return (T) attributes.get(key);
058    }
059
060    public Map<String, Object> getAttributes() {
061        return attributes;
062    }
063
064
065}