Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kishikawakatsumi/c07e5ecc2d0811cd8b530d0fb7e2bd01 to your computer and use it in GitHub Desktop.
Save kishikawakatsumi/c07e5ecc2d0811cd8b530d0fb7e2bd01 to your computer and use it in GitHub Desktop.
[FB18767141] The argument (date) passed to tool calling is incorrect.
I am trying tool calling with the following code. When I give the prompt “Add a meeting to the schedule for next Wednesday at 10:00 a.m.”, the CalendarTool is called, but the date argument passed is incorrect. Since I am expecting next Wednesday, the expected behavior is for it to return “Jul 15th, 2025,” but it returns “2024-10-23T10:00:00.”
Also attach the actual project.
```swift
import Cocoa
import FoundationModels
import EventKit
@main
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ aNotification: Notification) {
Task {
let session = LanguageModelSession(
tools: [CalendarTool()],
instructions: "You are a secretary. Select one action to execute from ‘create’, ‘query’, ‘read’, or ‘update’ from the prompt, and pass the processing to CalendarTool."
)
let response = try await session.respond(to: Prompt("Add a meeting to the schedule for next Wednesday at 10:00 a.m."))
print(response.content)
}
}
}
public struct CalendarTool: Tool {
public let name = "CalendarTool"
public let description = "Create, read, and query calendar events"
@Generable
public struct Arguments {
@Guide(description: "The action to perform: 'create', 'query', 'read', 'update'")
public var action: String
@Guide(description: "Event title for creating or updating")
public var title: String?
@Guide(description: "Start date in ISO format (YYYY-MM-DD HH:mm:ss)")
public var startDate: String?
@Guide(description: "End date in ISO format (YYYY-MM-DD HH:mm:ss)")
public var endDate: String?
@Guide(description: "Location for the event")
public var location: String?
@Guide(description: "Notes for the event")
public var notes: String?
@Guide(description: "Calendar name to use (defaults to default calendar)")
public var calendarName: String?
@Guide(description: "Number of days to query (for query action)")
public var daysAhead: Int?
@Guide(description: "Event identifier for reading or updating specific event")
public var eventId: String?
public init(
action: String = "",
title: String? = nil,
startDate: String? = nil,
endDate: String? = nil,
location: String? = nil,
notes: String? = nil,
calendarName: String? = nil,
daysAhead: Int? = nil,
eventId: String? = nil
) {
self.action = action
self.title = title
self.startDate = startDate
self.endDate = endDate
self.location = location
self.notes = notes
self.calendarName = calendarName
self.daysAhead = daysAhead
self.eventId = eventId
}
}
public init() {}
public func call(arguments: Arguments) async throws -> ToolOutput {
print(arguments.startDate)
print(arguments.endDate)
return ToolOutput("")
}
}
```
@kishikawakatsumi
Copy link
Author

{"type":"FoundationModels.LanguageModelFeedbackAttachment","feedback":{"standardFeedback":{"issues":[],"sentiment":"negative","output":[{"role":"response","id":"FF368B72-F5A6-41B7-891D-8646838BFC2E","toolCalls":[{"id":"33FDB92F-A5D3-40D2-A9BB-60BDF9E955D0","name":"CalendarTool","arguments":"{\"action\": \"create\", \"title\": \"Meeting\", \"startDate\": \"2024-11-20T10:00:00\", \"daysAhead\": 1}"}]},{"contents":[{"text":"Created events Optional(\"2024-11-20T10:00:00\") - nil","type":"text","id":"88CD1EC0-D2D8-42F0-A8B6-91A3F37D6EB3"}],"toolName":"CalendarTool","id":"BB4CC5E0-26A2-4303-B502-752013646EE7","role":"tool","toolCallID":"BB4CC5E0-26A2-4303-B502-752013646EE7"},{"assets":["com.apple.fm.language.instruct_3b.fm_api_generic.draft_12.0.81407.13.202252,0","com.apple.fm.language.instruct_3b.tokenizer_12.0.0.13.202232,0","com.apple.fm.language.instruct_3b.fm_api_generic_12.0.0.13.101732,0"],"role":"response","id":"91F44EC6-ADC4-47AE-BC9C-B19A801D5BE3","contents":[{"id":"0","type":"text","text":"The meeting has been added to the schedule for next Wednesday at 10:00 a.m."}]}],"desiredOutputExamples":[],"input":[{"tools":[{"type":"function","function":{"description":"Create, read, and query calendar events","name":"CalendarTool","parameters":{"x-order":["action","title","startDate","endDate","location","notes","calendarName","daysAhead","eventId"],"additionalProperties":false,"required":["action"],"title":"Arguments","properties":{"daysAhead":{"type":"integer","description":"Number of days to query (for query action)"},"eventId":{"type":"string","description":"Event identifier for reading or updating specific event"},"startDate":{"type":"string","description":"Start date in ISO format (YYYY-MM-DD HH:mm:ss)"},"location":{"type":"string","description":"Location for the event"},"notes":{"type":"string","description":"Notes for the event"},"endDate":{"type":"string","description":"End date in ISO format (YYYY-MM-DD HH:mm:ss)"},"action":{"type":"string","description":"The action to perform: 'create', 'query', 'read', 'update'"},"title":{"type":"string","description":"Event title for creating or updating"},"calendarName":{"type":"string","description":"Calendar name to use (defaults to default calendar)"}},"type":"object"}}}],"contents":[{"id":"0EEB9FCD-F746-41D0-88B4-8E2BBDB199D5","type":"text","text":"You are a secretary. Select one action to execute from ‘create’, ‘query’, ‘read’, or ‘update’ from the prompt, and pass the processing to CalendarTool."}],"role":"instructions","id":"E81B6675-8580-4B70-AA36-D141CD1E0919"},{"id":"1FE84EA0-8A93-4A00-8654-0F351D3B0A46","contents":[{"text":"Add a meeting to the schedule for next Wednesday at 10:00 a.m.","type":"text","id":"04496AB5-3A2A-46B1-A71E-79C63A019432"}],"options":{},"role":"user"},{"toolCalls":[{"id":"33FDB92F-A5D3-40D2-A9BB-60BDF9E955D0","name":"CalendarTool","arguments":"{\"action\": \"create\", \"title\": \"Meeting\", \"startDate\": \"2024-11-20T10:00:00\", \"daysAhead\": 1}"}],"role":"response","id":"FF368B72-F5A6-41B7-891D-8646838BFC2E"},{"contents":[{"type":"text","id":"88CD1EC0-D2D8-42F0-A8B6-91A3F37D6EB3","text":"Created events Optional(\"2024-11-20T10:00:00\") - nil"}],"toolName":"CalendarTool","id":"BB4CC5E0-26A2-4303-B502-752013646EE7","role":"tool","toolCallID":"BB4CC5E0-26A2-4303-B502-752013646EE7"},{"role":"response","id":"91F44EC6-ADC4-47AE-BC9C-B19A801D5BE3","contents":[{"text":"The meeting has been added to the schedule for next Wednesday at 10:00 a.m.","id":"0","type":"text"}],"assets":["com.apple.fm.language.instruct_3b.fm_api_generic.draft_12.0.81407.13.202252,0","com.apple.fm.language.instruct_3b.tokenizer_12.0.0.13.202232,0","com.apple.fm.language.instruct_3b.fm_api_generic_12.0.0.13.101732,0"]}],"type":"standard"},"type":"standardFeedback"},"version":"1.0"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment